drcmue4619 2014-05-28 14:58
浏览 67

将MySQL搜索输出限制为10

I am trying to create a social network. In the profile details I want to display at least 10 friends of that profile user. I used:

$connect = mysqli_connect("...","...","...","dbname"); //NOT REALLY IMPORTANT
$find = "SELECT * FROM friendslist WHERE user1 = '$myusername'";
$exec = mysqli_query($connect,$find);

while($row=mysqli_fetch_assoc($exec)) {
$friendusername = $row['user2'];

$con2 = "SELECT * FROM users WHERE username = '$friendusername' ";
$exec2 = mysqli_query($con,$con2);
$row2 = myslqi_fetch_assoc($exec2);

echo $row2['firstname']."<br/>";

My tables:

FOR friends:
id, user1, user2

FOR users
id, username, firstname

It will display all my friends like if I have 20 friends, it will display all 20 of them. How can I limit it to display only 10?

  • 写回答

3条回答 默认 最新

  • dqyq88053 2014-05-28 15:00
    关注

    Try:

    $find = "SELECT * FROM friendslist WHERE user1 = '$myusername' LIMIT 0, 10";
    
    评论

报告相同问题?