Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Location
    Texas
    Posts
    56
    Thanks
    6
    Thanked 3 Times in 3 Posts

    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.
    Last edited by Camron467; 05-07-2009 at 04:39 AM.
    Free PSD to XHTML/CSS conversion - Dimby.net
    Which doctype should I use?

  • #2
    New Coder
    Join Date
    Feb 2009
    Location
    Texas
    Posts
    56
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •