0

我编写了这些代码行来创建我的动态(从数据库中获取数据)复选框。

**<?php 

   db_connect();

   $sql = mysql_query('SELECT title  FROM products WHERE cname LIKE "Coffee"') or die(mysql_error());     

   while($row = mysql_fetch_array($sql, MYSQL_BOTH)){
       echo "<input type='checkbox' name='products[]' value='".$row['title']."'>"
        .$row['title'];
   }

?>**

问题是结果在我的网页中出现在同一行,但我希望它们以列表的形式出现,以便创建我自助餐厅的订单列表/菜单。我该如何纠正?

4

5 回答 5

3

改变:

while($row = mysql_fetch_array($sql, MYSQL_BOTH)){
    echo "<input type='checkbox' name='products[]' value='".$row['title']."'>"
     .$row['title'];
}

echo "<ul>\n":
while($row = mysql_fetch_array($sql, MYSQL_BOTH)){
    echo "<li><input type='checkbox' name='products[]' value='".$row['title']."'>"
     .$row['title']."</li>";
}
echo "</ul>\n":
于 2013-09-23T17:34:57.887 回答
0

You could put them in to a unordered list (UL):

<ul>
<?php 
db_connect();

$sql = mysql_query('SELECT title  FROM products WHERE cname LIKE "Coffee"') or die(mysql_error());

while($row = mysql_fetch_array($sql, MYSQL_BOTH)){
echo "<li><input type='checkbox' name='products[]' value='".$row['title']."'>"
    .$row['title']."</li>";}

?>
</ul>
于 2013-09-23T17:41:09.707 回答
0
<?php 

   db_connect();

   $sql = mysql_query('SELECT title  FROM products WHERE cname LIKE "Coffee"') or die(mysql_error());     

   while($row = mysql_fetch_array($sql, MYSQL_BOTH)){
       echo "<input type='checkbox' name='products[]' value='".$row['title']."'>"
        .$row['title']."<br/>";
   }

?>
于 2013-09-24T07:02:36.267 回答
0

试试这个:

<?php
db_connect();
$sql = mysql_query('SELECT title  FROM products WHERE cname LIKE "Coffee"') or     die(mysql_error());
echo "<ul>";
while($row = mysql_fetch_array($sql, MYSQL_BOTH)){

echo "<li> <input type='checkbox' name='products[]' value='".$row['title']."'></li>"
    .$row['title'];}//end while

echo"</ul>";
于 2013-09-23T17:34:52.817 回答
0

好吧,最简单<br />的解决方案是在每一行之后添加换行符 ( )。

你也可以使用一张桌子。例如,类似:

<?php 
    echo '<table>';
    while($row = mysql_fetch_array($sql, MYSQL_BOTH)){
        echo "<tr><td>";
        echo "<input type='checkbox' name='products[]' value='".$row['title']."'>";
        echo $row['title'];
        echho "</td></tr>";
   }
   echo '</table>'
?>

但是有更好的选择,包括divs 和 CSS。

于 2013-09-23T17:36:34.257 回答