【问题标题】:cant manage showing products from categories in php无法管理在 php 中显示类别中的产品
【发布时间】:2013-02-08 13:23:54
【问题描述】:
<?php 
// This block grabs the whole list for viewing
include "storescripts/connect_to_mysql.php";
$cat=$_POST['cat'];
$sql = mysql_query("select * from categories,products_cat,products where categories.id=products_cat.cat_id and products.id=products_cat.prod_id and categories=$cat");
$catCount = mysql_num_rows($sql); // count the output amount
    while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
             $product_name = $row["product_name"];
             $price = $row["price"];
             $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
             $prod_list .= "category ID: $id - <strong>$product_name</strong> <br />";
    }

?>

我有这三个表: 1)产品表: id , product_name,price,category,subcategory

2) 类别表: 身份证,猫

3) products_cat 表: cat_id, prod_id

我无法显示用户将从命令行输入的特定类别的产品 cat=x ,它只会给我这个错误:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/perzul12/public_html/beta/show.php on line 6

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/perzul12/public_html/beta/show.php on line 7

请帮帮我!这是我这个月唯一的金钱来源,我做不到!

【问题讨论】:

  • 请先使用mysqli_()而不是mysql_()来帮助我们
  • 我应该使用 mysqli_num_rows 而不是 mysql_num_rows ??

标签: php mysql


【解决方案1】:

这里的工作不在已弃用的mysql_ 函数中。相反,您没有返回有效的结果集。试试这个。

"select products_cat.products, categories.* 
from categories,
left join products_cat on products_cat.cat_id=products.id
where categories={$cat}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多