PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
while($row = mysql_fetch_array($results, MY
SQL_ASSOC)) {
$count+=1;
$asdf = mysql_query("SELECT * from pictures, user_ads where pictures.adID = '$rowїadID]'");
while($apic = mysql_fetch_array($asdf, MYSQL_ASSOC)) {
echo "$apicїsrc] : : : $count<br>";
}
however, it seems the right images are printed but they are printed once for each ad in search query. I only want them printed once, (may be more than one image ascosiated with an ad). Whats wrong with the code?
Hi, I think the problem is that you are not joining the user_ads table and the pictures table in the query, so mysql is returning lots or unrelated rows. Does that make sense?
Anyway, try adding the following to the WHERE condition:
Samscripts is absolutely correct, what you have is known as a Cartesian product because you did not join all the tables.
Basically every record in 1 table gets joined to every record in the other table, so if you have 1 table with 1000 records and 1 table with a million records doing a query like this would produce 1 billion record result set and take forever to run.
samscripts said "Anyway, try adding the following to the WHERE condition", rather than 'TRY' you must ALWAYS join your tables.