Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:52:23+00:00 2026-06-11T16:52:23+00:00

I have a query that selects all the users from my table. Then my

  • 0

I have a query that selects all the users from my table. Then my while loop loops through it. If the current user is friends with the user in the queried row the row of data is skipped, if not, then the row is displayed. How can I make this while loop stop after 3 successful rows are display? Just to be clear, not just 3 rows can be queried.

Here is my code:

                $query_know="SELECT * FROM users ORDER BY RAND()";
                $result_know= mysqli_query($connect, $query_know);
                $i= 0;
                    while ($row_know= mysqli_fetch_array($result_know)) {
                        $query_friend_test= "SELECT * FROM relations WHERE user1= '".$user_id."' AND user2= '".$row_know['user_id']."'";
                        $result_friend_test= mysqli_query($connect, $query_friend_test);
                            if (mysqli_num_rows($result_friend_test) > 0) {
                                continue;
                            }
                            else {
            ?>

            <div class="user-mini">
                <div class="user-mini-left">
                </div>
                <div class="user-mini-right">
                        <div class="story-user-mini">
                            <p><a href="<?php echo "profile.php?id=" . $row_know['user_id']; ?>"> <?php echo $row_know['fname'] . " " . $row_know['lname']; ?> </a></p>
                        </div>
                        <div class="story-content-mini">
                            <p> Ohio University </p>
                        </div>
                </div>
            </div>

            <?php
            }
            }

            ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:52:25+00:00Added an answer on June 11, 2026 at 4:52 pm

    For whatever $n number of rows you want to display:

    for($i = 0; $i < $n; $i++) {
        $row_know = mysqli_fetch_array($result_know);
    
        ... rest of code ...
    
    }
    

    When putting it in a for loop, it means you’re doing it only from $i = 0 to $i < $n, and when you use a while loop, you’re doing it forever, that is until you issue a break statement somewhere. If the number of rows is definite, you can use for.

    EDIT: I meant to say for, not foreach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that basically combines tables of actions and selects from them
So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
So I have this query that pulls from my links and votes table and
Dear all, I have a select query that currently produces the following results: DoctorName
I have a query that selects rows in a ListView without having a limit.
I have a SELECT query that I am expecting millions of results from. I
I have a query that looks like this SELECT * from myTable WHERE Date
I have a query that looks a bit like this: SELECT weekEnd, MAX(timeMonday) FROM
I have a working mysql query that retrieves data from table1. Now I will
I have a usermessages table in which all messages sent between two users on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.