CREATE TABLE `friends` (
`id` int(11) NOT NULL,
`user_one` varchar(55) NOT NULL,
`user_two` varchar(55) NOT NULL,
`friendship_official` enum('0','1') NOT NULL)
CREATE TABLE `registration` (
`user_id` int(11) NOT NULL,
`u_firstname` varchar(100) NOT NULL,
`u_lastname` varchar(100) NOT NULL,
`u_name` varchar(100) NOT NULL,)
这是我的PHP代码,我仍然没有任何html代码。任何人都可以在html中回显这些名称并更正此代码
$friendsArray = "";
$countFriends = "";
$friendsArray12 = "";
$addAsFriend = "";
$selectFriendsQuery = mysqli_query($con,"SELECT * FROM friends WHERE user_one=`$username` and friendship_official=`1`");
$friendRow = mysqli_fetch_array($selectFriendsQuery);
$friendArray = $friendRow[`user_two`];
if ($friendArray != "") {
$countFriends = count($friendArray);
$friendArray12 = array($countFriends);
$i = 0;
}
if ($countFriends != 0) {
foreach($friendArray12 as $key=>$value) {
$i++;
$getFriendQuery = mysqli_query($con,"SELECT * FROM registration WHERE u_name=`$value` LIMIT 1");
$getFriendRow = mysqli_fetch_array($getFriendQuery);
$friendUsername = $getFriendRow[`u_name`];
$friendFirstname = $getFriendRow[`u_firstname`];
$friendLastname = $getFriendRow[`u_lastname`];
} }
任何技巧都可以运用
答案 0 :(得分:0)
这是您的朋友桌
<?php
// $username must be unique
$friendsArray = array();
$html='';
$selectFriendsQuery = mysqli_query($con,"SELECT * FROM friends WHERE user_one=`$username` and friendship_official=`1`");
$countFriends = mysqli_num_rows($selectFriendsQuery);
if ($countFriends>0) {
$html.="<table>
<tr>
<th>Username</th>
<th>Full Name</th>
</tr>";
while($row=mysqli_fetch_array($selectFriendsQuery)) {
$user=$row['user_one'];
$getFriendQuery = mysqli_query($con,"SELECT * FROM registration WHERE u_name=`$user` LIMIT 1");
$getFriendRow = mysqli_fetch_array($getFriendQuery);
$html.="<tr>";
$html.= "<td>".$getFriendRow['u_name']."</td>";
$html. = "<td>".$getFriendRow['u_firstname'].' '.$getFriendRow['u_lastname']."</td>";
$html.="</tr>";
}
$html.="</table>";
}
echo $html;