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 8330243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:04:00+00:00 2026-06-09T02:04:00+00:00

I have a loop that should display a summary of all MySQL results. It

  • 0

I have a loop that should display a summary of all MySQL results. It does this by determining how may results there will be and then loops that many times. So if there are 43 results that match my query, instead of displaying all 43 results, it only displays the first result 43 times. Please help! Here’s my code:

if (empty($res)) {

echo 'No results found';

} else if($num>1){

    echo "<b>".$num_rows."<b> results found...<br>";

    while ($res = mysql_fetch_assoc($result)) {

    echo "<a href='#'>{$res['dealer']}</a><br>";

    }

} else {

echo "<table border=\"0\"><tr><td colspan=\"2\"><span class=\"dealer\">" . $res['dealer'] . "</span></td></tr><tr><td><span class=\"label\">Pin: </span><span class=\"inf\">" . $res['pin'] . "</span></td><td><span class=\"label\">OB CODE: </span><span class=\"ob\">" . $res['ob'] . "</span></td></tr><tr><td><span class=\"label\">Program Director:</span></td><td><span class=\"inf\">" . $res['contact'] . "</span></td></tr><tr><td valign=\"top\"><span class=\"label\">Address:</span></td><td><span class=\"inf\">" . $res['address'] . "<br>" . $res['city'] . ", " . $res['state'] . "<br>" . $res['zip'] . "</span></td></tr><tr><td><span class=\"label\">Dealer Phone:</span></td><td><span class=\"inf\">" . $res['phone'] . "</span></td></tr><tr><td><span class=\"label\">Codes Valid on:</span></td><td><span class=\"inf\">" . $res['website'] . "</span></td></tr></table>";

}

Thanks a lot in a advance!

  • 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-09T02:04:02+00:00Added an answer on June 9, 2026 at 2:04 am

    That’s because you’ve only fetched the first row (when you did $res = mysql_fetch_assoc($result);). What you’re trying to do is actually unnecessary: mysql_fetch_assoc() will automatically move the data pointer ahead every time it runs. What you can do instead (and is in fact common practice) is this:

    //...
    while ($res = mysql_fetch_assoc($result)) {
        echo "<a href='#'>{$res['dealer']}</a><br />";
    }
    //...
    

    On a side note, the mysql_* functions are soon to be deprecated. You can use either mysqli or PDO instead; if you’re a lazy bum with a lot of code to switch (like me), you can use the mysqli procedural functions – they’re almost identical to the original mysql_* functions.

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

Sidebar

Related Questions

I have this code that should display a clock on the first line of
I have a loop that calculates the similarity between two documents. It collects all
I have a loop that goes through all the news items we have on
I have a loop that can look like this: For Each article In artAll
I have a MySQL database that looks like this: users ( id , name
So I have a loop that is displaying all pages (not posts) on my
I have a loop that enters each non-empty text field into a database: foreach
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that runs through a variety of websites and I'd like
I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100

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.