View Full Version : Resolved WHILE inside WHILE - problem shows double

05-07-2009, 03:39 AM
I am a newbie to php, and in an attempt to create a script for my website I have come up with a problem that I am sure there is a simple answer to, I just can't find.

I have three tables in my data base.


ID (primary)
name [name of video]
embed [html embed]
Author [author name]
thumburl [thumbnail url]
description [descroiption]
Active [is it active? y or n]


contains category name and category id
the only category I am currently working on it category 1


conatins the Video id (vid) that corrosponds to cat ID (cid)

I am trying to get my code to find all video IDs that match the category ID 1 in the third table, and then from that output some of the information from table one. Here is my code.

$result = mysql_query("SELECT * FROM vidcat WHERE cid='1'");

while($row = mysql_fetch_array($result))
$vid = $row['vid'];
$result2 = mysql_query("SELECT * FROM idname WHERE active='y'");
while($row2 = mysql_fetch_array($result2))
echo('<img src="'.$row2["thumburl"].'" /><br />');
echo ('<a href="video.php?id='. $vid .'">'. $row2["name"] .'</a><br />');
echo ('<b>'.$row2["Author"].'</b><br /><br />');

Now, it may seem obvious to you, but I am a complete beginner and I do not know what I am doing wrong.

It is showing double of everything. The second one's link is different from the first one.

05-07-2009, 04:39 AM
Nevermind, I figured it out. I needed to make the query use a JOIN, then there would only be one while.