I am trying to implement the following code. What I want is to fetch the product id with column name prod_id
from the table cart_details
and then fetch the details for that product id with column name prod_id
from the table products
. But this code is not returning anything. Does this means that mysqli_query()
calls cannot be nested?
<?php
$cart_id=$_POST['q'];
include "connection.php";
$cart_id=mysqli_real_escape_string($link,$cart_id);
$query="select product_id from cart_details where cart_id = $cart_id";
$result=mysqli_query($link,$query) or die(mysqli_error($link));
if($result)
{
while($row=mysqli_fetch_array($result))
{
$prod_id = $row['product_id'];
$prodDetail = "Select * from products where prod_id = $prod_id";
$prodResult = mysqli_query($link,$prodDetails) or die(mysqli_error($link));
if(!$prodResult){
echo "There was an error in fetching the product with product ID ".$prod_id;
}
else{
if(mysqli_num_rows($prodResult)==0)
{
echo "There is no item in this cart";
}
else{
while($prod=mysqli_fetch_array($prodResult)){
$prod_name=$prod['prod_name'];
$prod_price=$prod['prod_price'];
echo "<tr><td>".$prod_id."</td>";
echo "<td>".$prod_name."</td>";
echo "<td>".$prod_price."</td></tr>";
}
}
}
}
}
else{
echo "Query Failed";
}
?>