我正在使用 PHP 创建一个小型网站,该网站通常是展示医院的网站,我修改了此示例中给出的代码: https ://www.w3schools.com/php/php_mysql_select.asp
<?php
$query = "SELECT * FROM emp WHERE type = 'woman' ";
$result = mysqli_query($db, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$cat = $row["cat"] . ',';
echo $cat;
////<---- echo on while (Loop)
}
}
预期输出如下:
Output: 35,36
但是我用上面的链接更改了代码,如下所示:
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$cat = $row["cat"] . ',';
}
echo $cat;
///// <---- echo Out of While (Loop)
}
Output: 35
我的预期输出将是使用“echo”在“while”之外的 35、36。
你推荐什么代码输出“35,36”上面相同的代码?
慕丝7291255