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 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Selecting Related Info?

    I have two tables that are related. A Video table and a Information table. I use a video_id column in the Infomoration table to link the videos with their relevant pieces of information. The problem I have is trying to get them both out at the same time.

    For example, if I select all the videos I need on a given page and store it as $videos, how would I then go about selecting all the pieces of information per-video? Would I need a two dimensional array?


    For example:

    $vid_info[0][0] = first vid, first info
    $vid_info[0][1] = first vid, second info

    What would be my select statement to even grab the info?

    Thanks!!

  • #2
    New Coder
    Join Date
    Oct 2010
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts
    By the way, I'm not just asking for answers, I've tried several different methods that failed, and one that worked.

    The one that worked seems really inefficient though as it requires a select statement to be inside of a while loop. This was just a test but the idea works. I am very open to other suggestions!

    PHP Code:
                while($row mysql_fetch_array($video)){
                    
    $vid_id $row['id'];
                    
    $infomysql_query("SELECT * FROM Video_Information
                    WHERE video_id='$vid_id' ORDER BY info_order"
    );
                    while(
    $row2 mysql_fetch_array($info)){
                        echo 
    $row2['video_info'];
                    } 
    Last edited by rootmath; 06-29-2011 at 01:37 AM. Reason: typo/clarification

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I found a solution for anyone who comes across this:

    Select:
    PHP Code:
        $i=0;
        while(
    $row=mysql_fetch_array($video)){
            
    //Get the id for each video
            
    $video_id=$row['id'];
            
    //Create an Array of foundation information based on the video ID
            
    $foundation[$i] = mysql_query("SELECT * FROM Foundation
            WHERE video_id='$video_id' ORDER BY foundation_order"
    );
            
            
    $i++;
        } 
    Display:
    PHP Code:
    $i=0
    while($row mysql_fetch_array($foundation[$i])){
          echo 
    '<li>'.$row['foundation_info'].'</li>';
                                    } 


  •  

    Posting Permissions

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