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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile How To: Get data out of related tables and output it nicely?

    Hey Guys, What a top forum! I just started getting into PHP a week ago, I saw the light, stopped my ASP progress and gave in to PHP.

    So I really need help now with an issue, I have done my utmost to describe and show you guys the issue in as much relevant detail as possible here:
    http://www.camtutor.net/problem.html

    Please help me out I have spent a day scouring the web, w3school.com, www.php-mysql-tutorial.com, deeptraining.com and lots of other but I just can't put it together and my head hurts.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    explain your problem here, half the text is missing when I look at that page.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    If your issue is displaying the data then this thread belongs in the php forum. Post mysql query related problems in the mysql forum please.

  • #4
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying again

    Okay thanks for the responses guys. I'll try to explain the problem again.

    So what I'm trying to do is get it to output the lessons and their corresponding media displayed something like the below

    lesson_ID(1)
    - media_ID(corresponding mapped in lnk_lessons_media table)
    - media_ID(corresponding mapped in lnk_lessons_media table)

    lesson_ID(2)
    - media_ID(corresponding mapped in lnk_lessons_media table)
    - media_ID(corresponding mapped in lnk_lessons_media table)

    etc...

    Tables are here:


    The PHP:
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","xxxxxx","xxxxxxx"); //mysql_connect(servername,username,password);
    if (!$con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("tables"$con
            or die(
    "Error Could not select database");

    $result_lessons mysql_query("
    SELECT * 
    FROM 
    (lessons INNER JOIN lnk_lessons_media ON lessons.lesson_ID = lnk_lessons_media.lesson_ID) 
    INNER JOIN 
    media ON lnk_lessons_media.media_ID=media.media_ID
    "
    ); 

    while(
    $row mysql_fetch_array($result_lessons))
        {
        
        echo 
    "{$row['lesson_ID']} | {$row['lesson_title']} | {$row['media_ID']} | {$row['media_title']} <br />";        
        
        }

     
    mysql_close($con); //closes the database connection

    ?>
    so far the only output I can achieve is this:

    1 | Ni Hao | 1 | Ni Hao Flash Lesson
    1 | Ni Hao | 2 | Teacher goes crazy Flash Lesson
    2 | Eating with your Teeth | 3 | 1st Media for lesson 2
    2 | Eating with your Teeth | 4 | 2nd Media for Lesson 2

    Not what I'm wanting.... Thanks guys! Its baking my little noodle!
    Last edited by neillglobal; 02-28-2007 at 08:52 AM.

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Looks like you've got the data you need, you just need to use some looping fun to display it right. I'd probably go old-school like this:
    PHP Code:
    $previousLessonID '';
    while(
    $row mysql_fetch_array($result_lessons))
        {
        
        if (
    $row['lesson_ID'] != $previousLessonID) {
            echo 
    "Lesson {$row['lesson_ID']}: {$row['lesson_title']}<br />\n";
        }
        echo 
    "{$row['media_ID']} | {$row['media_title']} <br />\n";
        
    $previousLessonID $row['lesson_ID'];
        
        } 

  • #6
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Fumigator!!!!

    That worked like a charm!!!!!! Now I'm back on track! Legendary!

    Hey if that's old-school... whats new-school? Thats a serious question there

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Hehe... I'm sure some young wizkid has a new way of what we used to call "control breaks", and will be quick to point out how horrible that old way is. It's the cycle of life, new technology poo-poos old technology (even though the old way may work just fine).


  •  

    Posting Permissions

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