如何將其製作爲單個查詢。我制定了以下查詢:如何使這些查詢進行子查詢?
$msgs=mysql_query("select m.subject, m.msg from message as m, message_users as mu where m.id=mu.msg_id and mu.user_id=$u_id order by dateof_msg desc");
while($row1=mysql_fetch_array($msgs))
{
$total_msg = $row1['msg'];
$own_id = mysql_query("select owner_id from message where msg='$total_msg' ");
while($o_id=mysql_fetch_array($own_id))
{
$owners_id = $o_id['owner_id'];
$uname = mysql_query("select name from users where id='$owners_id'");
while($username=mysql_fetch_array($uname))
{
$sen_name = $username['name'];
echo $sen_name." ".$owners_id." ".$total_msg."<br />";
}
}
}
由於查詢的運行時間確實很慢。
我現在編輯的這樣的代碼,但它說mysql_fetch_array()節選參數1是資源布爾給出...
$userlist = mysql_query("select m.subject, m.msg, m.owner_id, u.name, u.id, mu.msg_id, mu.user_id from message as m, message_users as mu, users as u
m inner join u on (m.owner_id = u.id)
m inner join mu on(m.id=mu.msg_id) and
where mu.user_id='$u_id' order by dateof_msg desc") or mysql_error();
while($row=mysql_fetch_array($userlist))
{
$sendername = $row['name'];
echo $sendername;
}
這是因爲該查詢不正確。把這個:'$ userlist = mysql_query(「...」)或死(mysql_error());'你會看到錯誤。 – RainHeart257 2013-03-01 13:21:12