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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:28:09+00:00 2026-06-14T15:28:09+00:00

I have one record in a table in my mysql database. I use the

  • 0

I have one record in a table in my mysql database. I use the following PHP code to retrieve data:

$result = mysql_query($query = "SELECT realname FROM t_user");

if($result)
{
  while($data=mysql_fetch_assoc($result)){
    echo $data['realname'];
  }
}

the results do not appear, but when I use a do-while loop like below:

if($result)
{
  $data=mysql_fetch_assoc($result);
  do{
    echo $data['realname'];
  } while($data=mysql_fetch_assoc($result));
}

the results appear, then I tried to add one more record to the table, in the while loop, only shows one data record (the first record), and the do-while loop displays all the data. Why is that? Is it because there is my code wrong?

  • 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-14T15:28:10+00:00Added an answer on June 14, 2026 at 3:28 pm

    The code you have shown can’t possibly exhibit this problem, so the logical explanation is this:

    $result = mysql_query($query = "SELECT realname FROM t_user");
    
    if($result)
    {
      // Something fetched a row from $result before this statement is run
      while($data=mysql_fetch_assoc($result)){
        echo $data['realname'];
      }
    }
    

    Seeing how you’re comparing two similar codes, you may have accidentally written something in between the two:

    if($result)
    {
      mysql_fetch_assoc($result);
      while($data=mysql_fetch_assoc($result)){
        echo $data['realname'];
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have one php file which process adding of record in Database fro array.
I have only one table in my mySql database for a very basic website
PLATFORM: PHP, mySQL & jQuery WHAT I HAVE: I have a Database table. Within
MYSQL Database: I have a table of data that I need to put into
I have a table in my MySQL database containing 200K records. Each record contains
Ok, so i have one really monstrous MySQL table (900k records, 180 MB total),
I have a mysql table that have several records linked to one particular tag.
I have one table TABLE_QUESTION. I need to fetch record by passing exam_id and
I have a dataset with multiple tables. One table in particular has one record
I'm trying to use the following query syntax from a php file: $sql =

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.