我遇到了一个问题,因为我正在测试一个消息传递程序,但它没有用。 我想展示用户的谈话,但是evreything仍然是空白的。 这是代码:
<?php
include_once('config.php');
include_once('functions.php');
$user_one = "13";
$db = safe_db_open($host, $gebruiker, $wachtwoord, $database);
$query= ("SELECT u.user_id,c.c_id,u.username,u.email
FROM conversation c, users u
WHERE CASE
WHEN c.user_one = '$user_one'
THEN c.user_two = u.user_id
WHEN c.user_two = '$user_one'
THEN c.user_one= u.user_id
END
AND (
c.user_one ='$user_one'
OR c.user_two ='$user_one'
)
Order by c.c_id DESC Limit 20");
$result = safe_query($db, $query);
while($row = mysqli_fetch_array($result))
{
$c_id=$row['cid'];
$user_id=$row['user_id'];
$username=$row['username'];
$email=$row['email'];
$cquery= ("SELECT R.cr_id,R.time,R.reply FROM conversation_reply R WHERE R.c_id_fk='$c_id' ORDER BY R.cr_id DESC LIMIT 1");
$cresult = safe_query($db, $cquery);
$crow= mysqli_fetch_array($cresult);
$cr_id=$crow['cr_id'];
$reply=$crow['reply'];
$time=$crow['time'];
echo "$time : $reply";
}
答案 0 :(得分:0)
试试这个:
<?php
include_once('config.php');
include_once('functions.php');
$user_one = "13";
$db = safe_db_open($host, $gebruiker, $wachtwoord, $database);
$query= ("SELECT u.user_id, c.c_id, u.username, u.email
FROM conversation c, users u
WHERE CASE
WHEN c.user_one = '{$user_one}'
THEN c.user_two = u.user_id
WHEN c.user_two = '{$user_one}'
THEN c.user_one = u.user_id
END
AND (
c.user_one = '{$user_one}'
OR c.user_two ='{$user_one}'
)
ORDER BY c.c_id DESC LIMIT 20");
$result = safe_query($db, $query);
while($row = mysqli_fetch_array($result))
{
$c_id = $row[cid];
$user_id = $row[user_id];
$username = $row[username];
$email = $row[email];
$cquery = ("SELECT R.cr_id, R.time, R.reply FROM conversation_reply R WHERE R.c_id_fk='{$c_id}' ORDER BY R.cr_id DESC LIMIT 1");
$cresult = safe_query($db, $cquery);
$crow = mysqli_fetch_array($cresult);
$cr_id = $crow[cr_id];
$reply = $crow[reply];
$time = $crow[time];
echo "$time : $reply";
}
?>
<强> BUT:强> $ cquery中的R是什么? 如果它应该是&#34; conversation_reply R&#34;比如DB中的单元格名称,请尝试执行以下操作:
在include functions.php之后添加:
$helpvar = "conversation_reply R";
然后将$ cquery更改为:
$cquery= ("SELECT R.cr_id, R.time, R.reply FROM '{$helpvar}' WHERE R.c_id_fk='$c_id' ORDER BY R.cr_id DESC LIMIT 1");