0
我在我的數據庫中有一些信息,比如'author','book'等,這些信息都與'note_id'有關,這和'user'有關。我查詢數據庫的音符ID和我得到這個回:如何排序'object_id'數組,以便可以從數據庫獲取關係值?
note_id assoc命令陣列
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;
}
}
?>
是的。這是我以前做的,但我發現它有點太複雜,因爲我會從4個不同的表中獲取數據。 – Tapha 2010-03-03 04:20:07
如果它們都共享一個鏈接匹配記錄的公共ID,那麼加入4個表格的效率可能比運行4個查詢的效率要高得多。但是,如果你絕對不想使用連接,那麼你基本上會在循環內運行查詢,看起來像''SELECT field1,field2,... FROM othertable1 WHERE note_id = $ current_note_id;''然後得到結果對於每個查詢。 – Amber 2010-03-03 04:34:00