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

  • Home
  • SEARCH
  • 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 6779377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:22:41+00:00 2026-05-26T16:22:41+00:00

I am having issues with a while loop that draws data out of a

  • 0

I am having issues with a while loop that draws data out of a mysql database. Essentially, a user searches a string, the string is then compared against of possible names in the db. If a string matches a result from the db, then the row is returned and the information relating to the result is dislayed in its’ own div.

Here is the, somewhat faulty code relating to the while loop:

    (LOTS OF CODE RELATING TO EVERYTHING ELSE BEFORE THIS)
    $tempVar = 0;
while ($data = mysql_fetch_array($data)) {
    $lstId = $data['id'];
    $lstName = $data['name'];
    $lstDesc = $data['description'];
    $lstAddress = $data['address'];
    $lstArea = $data['area'];
    $lstProvince = $data['province'];
    $lstPostcode = $data['postcode'];
    $lstTel = $data['tel'];
    $lstCell = $data['cell'];
    $lstFax = $data['fax'];
    $lstEmail = $data['email'];

if ($tempVar == 0) {
    $pageContent .= '
        <div class="searchResultS">
    ';
    }
    $pageContent .= '
    <div class="searchResult">
    <h2>'.$lstName.'</h2>
        <div class="bizDesc">
            <p>Description: '.$lstDesc.'</p>
        </div>
        <div class="bizAddr">
            <p>Street: '.$lstAddress.'</p>
            <p>Town: '.$lstArea.'</p>
            <p>Province: '.$lstProvince.'</p>
            <p>Post Code: '.$lstPostcode.'</p>
        </div>
        <div class="bizCont">
            <p>Tel: '.$lstTel.'</p>
            <p>Cell: '.$lstCell.'</p>
            <p>Fax: '.$lstFax.'</p>
            <p>eMail: '.$lstEmail.'</p>
        </div>
    </div>
';
  $tempVar ++;
 }

if ($anymatches > 0 and count($tempVar) == count($anymatches)) {
        $pageContent .= '
    <!-- end .searchResultS --></div>
';
}

The problem that I am having, is that when a user searches a string with two or more possible results. It seems as though only the last result is displayed. And not all of the possible results, each in their own containing div. I know for a fact that there are more results, as there is a line generated that displayed the number of mysql rows returned.

Would anyone have a suggestion, or solution for this problem? I assume that something has been left out, but after many hours of trial and error testing, i have come up with no solid reason as to why this behavior currently exists.

Any help what so ever would be greatly appreciated, thank you!

  • 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-05-26T16:22:42+00:00Added an answer on May 26, 2026 at 4:22 pm

    Looks like you are overwriting the result resource $data to an array on the first loop iteration. After this iteration, $data can no longer be accessed as a result resource, so it will appear as though you’ve had only one result.

    while ($data = mysql_fetch_array($data)) {
    
    // Instead use a new variable:
    while ($row = mysql_fetch_array($data)) {
    //-----^^^^
    
    // Then change all of these
    $lstId = $row['id'];
    $lstName = $row['name'];
    $lstDesc = $row['description'];
    ...
    ...
    $lstEmail = $row['email'];
    

    You should turn on display_errors in development, as I would expect you to have received this warning after the first loop iteration:

    Warning: mysql_fetch_array() expects parameter 1 to be resource…

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

Sidebar

Related Questions

I'm having issues while populating a combobox using DirectStore, the combobox is as follow:
Hey I am having some issues while using Nggalley plugin for wordpress the plugin
I just recently started having issues while deploying EARS within websphere. The error I
I am new to PHP and I am having issues pulling this data in..
I seem to be having some issues while attempting to implement logging into my
I'm having some performance issues while developing Android apks. My machine is an AMD
I am having an issue handling HTTP URL Connections that do not return data.
I'm having issues transferring lazy loaded data over the wire using WCF and NHibernate.
I was having a problem with my function yesterday that turned out to be
We were having a performance issue in a C# while loop. The loop was

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.