gpt4 book ai didi

php - 使用 php mysql 从类别中获取数据

转载 作者:行者123 更新时间:2023-11-29 20:08:02 25 4
gpt4 key购买 nike

我尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com