【问题标题】:tell me why this is only returning 1 result告诉我为什么这只返回 1 个结果
【发布时间】:2015-01-13 13:49:43
【问题描述】:
$sql="SELECT * FROM oc_category where parent_id = '253' "; // grab the category id from the parent id
$result=mysqli_query($con,$sql);
$Pid=mysqli_fetch_assoc($result);

$sql="SELECT * FROM oc_category_description where category_id = '$Pid[category_id]' "; // grab the category name from the category id
$result=mysqli_query($con,$sql);
$Cid=mysqli_fetch_assoc($result);

 {
// show the results
echo '<a target="_top" href="index.php?route=product/products&product_id=' .    
$Cid['category_id'] . '"><span class="cat">' .  substr($Cid['category_id'], 0, 
50),('')  . '</span></a><br>' . '' . "\n";       
      }  

【问题讨论】:

  • 没有你的模式是不可能说出原因的。所以请分享架构。
  • 很抱歉,您所说的架构是什么意思?

标签: mysqli mysqli-multi-query


【解决方案1】:

我认为您最好进行连接 - 这样您就只有一个查询。您的新查询将是:

SELECT desc.* 
FROM oc_category cat, oc_category_description desc 
WHERE cat.parent_id = '253' 
and cat.category_id = desc.category_id

【讨论】: