Multiple mysql_fetch_array Conditions?

Hi guys, is it possible to have two conditions for a while loop? Please see my code below.

<html>
	<head>
		<title>Print Database</title>
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
</style>
	</head>
	<body>
	<?php
include_once('connection.php');
$query = "SELECT * FROM products_description ORDER BY products_name";
$result = mysql_query($query) or die (mysql_error());

$query1 = "SELECT products_price FROM products";
$result1 = mysql_query($query1) or die (mysql_error());

//Print out Results
while($row = mysql_fetch_array($result),$row1 = mysql_fetch_array($result1)){
	echo "<div style='width: 600px; background-color: #CCCCCC; margin-bottom: 10px; padding: 4px 4px 4px 4px;'>";
	echo "<div style='font-size: 12px; font-family: Arial, Helvetica, sans-serif; width: 40px; float: left;'>".$row['products_id']."</div>";
	echo "<div style='font-size: 12px; font-family: Arial, Helvetica, sans-serif; width: 40px; float: left;'>".$row1['products_price']."</div>";
	echo "<div style='font-size: 12px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; width: 370px;'>".$row['products_name']."</div>";

	echo "</div>";
}

?>
	</body>
</html>


while($row = mysql_fetch_array($result) [B][COLOR="Red"]&&[/COLOR][/B] $row1 = mysql_fetch_array($result1)){

Hi, I can see this should work but nothing seems to be displaying now from $row?

Both conditions have to be true. If one of the two fetches doesn’t return a row, the loop isn’t executed.

I think your problem is the two separate queries. How can you be sure the two fetches get rows that are related to eachother? Something tells me you should use one query, joining the two tables.

What is the relation between the products table and the products_description table?

Hi, ok I think I’ve worked out how to join the tables together. Everything is now displaying but I’m getting around 100 of each product instead of just the one in the database. I’m working on a work website, recently taken it over from the previous guy. My code now looks like:

<html>
<head>
<title>Print Database</title>
<style type=“text/css”>
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
</style>
</head>
<body>
<?php
include_once(‘connection.php’);
$query = “SELECT products.products_id, products_description.products_name, products.products_price FROM products, products_description”;
$result = mysql_query($query) or die (mysql_error());

//Print out Results
while($row = mysql_fetch_array($result)){
echo “<div style=‘width: 600px; background-color: #CCCCCC; margin-bottom: 10px; padding: 4px 4px 4px 4px;’>”;
echo “<div style=‘font-size: 12px; font-family: Arial, Helvetica, sans-serif; width: 40px; float: left;’>”.$row[‘products_id’].“</div>”;
echo “<div style=‘font-size: 12px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; width: 370px;’>”.$row[‘products_name’].“</div>”;
echo “<div style=‘font-size: 12px; font-family: Arial, Helvetica, sans-serif; width: 40px; float: right;’>”.$row[‘products_price’].“</div>”;
echo “</div>”;
}

?>
</body>
</html>


SELECT
    products.products_id
  , products_description.products_name
  , products.products_price
FROM products
[COLOR="Red"][B]INNER JOIN[/B][/COLOR] products_description
[B][COLOR="Red"]ON products.products_id = products_description.products_id[/COLOR][/B]

You forgot the join condition. If you don’t specify on what fields the join has to be done, the result will be a cross join: each row from table 1 will be joined to each row from table 2. So if table 1 has 10 rows, and table 2 has 5 rows, the query result will have 50 rows (10 x 5).

Above I assumed the two tables are to be joined on the products_id column. But I might be wrong. You didn’t post the table definitions, and you didn’t tell me what the relation between the two tables is.

That’s DONE IT! Perfect, thank you for your help. People are so quick and accurate in reply on this forum, I really do value it. Thanks again.