【发布时间】:2017-03-15 18:36:53
【问题描述】:
我需要一些 PHP 编码帮助来构建回显以显示数据库查询的结果...(列出登录用户的朋友?)我已经构建了大部分,但我不知道如何回显结果数据并将其链接到他/她的个人资料?任何帮助将不胜感激......也许是如何写出来的代码sn-p?
这是我的代码:
$query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($query);
if ($numrows > 0){
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
array_push($my_friends, $row["user2"]);
array_push($my_friends, $row["user1"]);
}
//remove your id from array
$my_friends = array_diff($my_friends, array($u));
//reset the key values
$my_friends = array_values($my_friends);
mysqli_free_result($query);
} else {
echo "You have no friends.";
}
// Build My friends From Results
****this is where I need help with*****
if (array_key_exists('0', $my_friends)){
$sql = "SELECT user1, user2
FROM friends
WHERE (user1='$u' OR user2='$u')
AND accepted='1'";
$result = mysqli_query($db_conx, $sql);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$my_friends = "<a href='user.php?u=".$result."'>". $row['avatar']. ' '. $row['firstname']. ' ' .$row['lastname'] ."</a>"; }
}
?>
Here is my html code:
<?php
echo "<li>$my_friends</li>";
?>
【问题讨论】:
-
您希望
links在 HTML 页面上的外观如何? -
我将它们放入一个按姓氏字母顺序自动划分的无序列表视图页面中,所以我希望它基本上扩展
- 内的
- ,然后每个项目将链接回来到该用户的配置文件 user.php?u="userid""