PHP 中的循环不工作
$qPhysician = mysql_query("SELECT * FROM physicians");
$num = mysql_num_rows($qPhysician);
$i=0;
while($i < $num)
{
"<tr>";
"<td>" . mysql_result($qPhysician,$i,"lastName") . "</td>";
"<td>" . mysql_result($qPhysician,$i,"firstName") . "</td>";
"</tr>";
$i++;
}
我得到空白结果。
如果我回显 $num
,我会得到“19”,这是我的数据库中的行数。 如果我 echo $rowPhysician['lastName']
只是为了测试是否获取记录,那么我至少会获取 1 条姓氏记录。不知道“while”有没有问题。请帮帮我。
$qPhysician = mysql_query("SELECT * FROM physicians");
$num = mysql_num_rows($qPhysician);
$i=0;
while($i < $num)
{
"<tr>";
"<td>" . mysql_result($qPhysician,$i,"lastName") . "</td>";
"<td>" . mysql_result($qPhysician,$i,"firstName") . "</td>";
"</tr>";
$i++;
}
I get blank result.
If I echo $num
, I get "19" which is the number of rows in my DB.
If I echo $rowPhysician['lastName']
just to test out if I get records, I get at least 1 record of last name. I don't know if there is something wrong with "while". Please help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否缺少打印字符串的回声?
Are you missing the echo to print out the strings?
从技术上讲,这不是一个答案,但以这种方式显示代码更容易:
在极少数情况下,mysql_result实际上是更好的选择——通常最好在 PHP 中填充几个数组,然后完成数据库。
Technically, this isn't an answer, but it is easier to show the code this way:
It is a very rare circumstance that mysql_result is actually a better option -- usually it is better to just populate a couple of arrays in PHP and be done with the DB.
不管怎样,回显 HTML 是不好的做法。更正确的输出应该类似于
注意,您也写了错误的关闭 HTML。
Anyways echo'ing HTML is bad practice. The more correct output could should look like
Note that you wrote closing HTML wrong, too.