如何对“object_id”数组进行排序,以便从数据库中获取关系值?

时间:2010-03-03 04:15:31

标签: php mysql

我的数据库中有一些信息,如'author','book'等,都与'note_id'相关,后者与'user'相关。我在数据库中查询了注释ID,我得到了回复:

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 ) 

我要做的是使用所有这些值来获取每本书评(包括作者,书籍等),然后逐个按顺序显示给用户。

我能够做到这一步的下一步是什么?

以下是我正在使用的代码:

<?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;
        }
    }   
?>

1 个答案:

答案 0 :(得分:0)

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