これを単一のクエリにする方法。次のクエリを作成しました。
$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 />";
}
}
}
クエリの長さのため、実行は非常に遅くなります。
私は今このようにコードを編集しましたが、パラメータ1を除いてmysql_fetch_array()はリソースブール値が与えられていると言います...
$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;
}