我想对一个返回多行和多列的mysql数据库进行查询。然后,我想将结果分配给变量,并在页面后面回显它们。但是,我使用的方法冗长乏味,而且这个项目不切实际。这就是我在做的事。
$result = mysql_query("SELECT * FROM people WHERE open_or_closed !='Closed' ORDER BY
number",$c) or die("two");
$number=mysql_num_rows($result);
if($mynumber>0){
$data= mysql_fetch_array($result,MYSQL_ASSOC);
$full_name1=mysql_result($result,0, 'full_name');
$phone_number1=mysql_result($result,0, 'phone_number');
$one=1;
}
if($mynumber>1){
$full_name2=mysql_result($result,1, 'full_name');
$phone_number2=mysql_result($result,1, 'phone_number');
$two=2;
}
后来当我想回应它时,我不知道是否有记录,所以我必须
<?php if($one==1){echo '<div id="blackline"></div>';}?>
<div id="titletext"><?php echo $full_name1; ?></div><br />
<div id="datetext"><?php echo $phone_number1; ?></div>
答案 0 :(得分:0)
试试这个
$result = mysql_query("SELECT * FROM people WHERE open_or_closed !='Closed' ORDER BY
number",$c) or die("two");
$number=mysql_num_rows($result);
if($number>0)
{
$i=0;
while($row_result = mysql_fetch_array($result))
{
$full_name[$i][] = $row_result['full_name'];
$phone_number[$i][] = $row_result['phone_number'];
$i++;
}
}