tags:

views:

14

answers:

1

I have some information in my database like 'author' 'book', etc that are all related to a 'note_id', which is related to a 'user'. I query the DB for the note id. and i get thus back:

*note_id assoc array*

Array ( [0] => 32 ) Array ( [0] => 31 ) Array ( [0] => 33 ) Array ( [0] => 34 ) Array ( [0] => 35 ) Array ( [0] => 36 ) Array ( [0] => 37 ) Array ( [0] => 38 ) Array ( [0] => 39 ) Array ( [0] => 40 ) Array ( [0] => 41 ) Array ( [0] => 42 ) Array ( [0] => 43 ) Array ( [0] => 44 ) Array ( [0] => 45 ) Array ( [0] => 46 ) 

What i am trying to do is use all of these values to grab each book review, (with author, book, etc.) then display it to the user in order. One by one.

What's the next step for me to be able to do this?

Here is the code i am using:

<?php

//Starting session

session_start();

//Includes mass includes containing all the files needed to execute the full script
//Also shows homepage elements without customs

include ('includes/mass.php');

//Set the  session variable

$username = $_SESSION['username'];


//Check to see if logged in

    if (isset($username))

        {

            //Check all databases assoc with the notes for username submissions

            $sql_for_username_submission = "SELECT note_id FROM notes WHERE user = '$username'";

            $get_data = mysql_query($sql_for_username_submission);

            while ($data_row = mysql_fetch_assoc($get_data))

                    {
                         $name_id = $data_row;

                    }

        }   


?>

Please help. I'm a bit lost on this one.

Thank you!

A: 

Have you considered looking into using joins so that you could have MySQL automatically lookup the data for you without separate queries?

Amber
Yes. That is what i did previously but i found that it was a bit too complicated because i will be fetching data from 4 different tables.
Tapha
If they all share a common ID linking matching records, it's probably actually far more efficient to join the 4 tables than it would be to run 4 queries. But if you absolutely do not want to use joins, then you'd basically run queries within the loop that look like `"SELECT field1,field2,... FROM othertable1 WHERE note_id = $current_note_id;"` and then get the result from that, for each query.
Amber