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());
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.