简体   繁体   中英

How can I sort an 'object_id' array so that I can get the relational values from the database?

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 this 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 to use all of these values to grab each book review (with author, book, etc.) and 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;
        }
    }   
?>

您是否考虑过使用联接,以便MySQL可以自动为您查找数据而无需单独查询?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM