我尝试使用 mysql 和 php 从类别中获取数据。
SQL 结构:
Category
-cat_id
-name
Date
-id
-url
-category
PHP 代码:
<?php
$sql = "select * from category";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
echo '<option value="'.$row["cat_id"].'">'.$row["name"].'</option>';
}
}
$sql = "select * from date WHERE category='1'";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
echo '.$row["url"].';
}
}
?>
当我选择类别时,数据未列出。 有什么想法吗?
最佳答案
试试这个代码。刚刚删除了单引号
$sql = "select * from date WHERE category='1'";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
echo $row["url"];
}
}
关于php - 使用 php mysql 从类别中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40275695/