Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2009, 02:39 AM   PM User | #1
Camron467
New Coder

 
Join Date: Feb 2009
Location: Texas
Posts: 56
Thanks: 6
Thanked 3 Times in 3 Posts
Camron467 is an unknown quantity at this point
WHILE inside WHILE - problem shows double

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.

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

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

vidcat
  • 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.

PHP 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.
__________________
Free PSD to XHTML/CSS conversion - Dimby.net
Which doctype should I use?

Last edited by Camron467; 05-07-2009 at 03:39 AM..
Camron467 is offline   Reply With Quote
Old 05-07-2009, 03:39 AM   PM User | #2
Camron467
New Coder

 
Join Date: Feb 2009
Location: Texas
Posts: 56
Thanks: 6
Thanked 3 Times in 3 Posts
Camron467 is an unknown quantity at this point
Nevermind, I figured it out. I needed to make the query use a JOIN, then there would only be one while.
__________________
Free PSD to XHTML/CSS conversion - Dimby.net
Which doctype should I use?
Camron467 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:43 AM.


Advertisement
Log in to turn off these ads.