I have a series of mysql queries within while loop.. just like this.
$sql = mysql_query("SELECT productid FROM cart WHERE userid='$userid'")
while($row = mysql_fetch_assoc($sql)){
$pid = $row['product_id'];
//Second one
$sql2 = mysql_query("SELECT barcode,quantity FROM products WHERE id='$pid'")`
while($row2 = mysql_fetch_assoc($sql2)){
$quantity = $row2['quantity'];
$barcode = $row2['barcode'];
//Third one
$sql3 = mysql_query("SELECT name,price FROM inventory WHERE product_barcode=$barcode");
while($row3 = mysql_fetch_assoc($sql3)){
$name = $row3['name'];
$price = $row3['price'];
echo $name.'<BR />'.$price.'<BR />.$quantity';
}
}
}
You can see that these queries are dependent on one another so used the while loop to get all possible results. But I don't think this way of querying is a good practice. It takes much time..Does it? I dont know.. Can anyone please edit and show me a better way of querying and output these similar queries. Thanks
$sql2and$sql3only return one row each?$sql2will return as many rows associated with$pidand$sql3will as many associated with$barcode... If it's one then one or if it's more then moreid = 2, for example? Isidnot unique? And the same withproduct_barcodein theinventorytable -- is it not unique?