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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:27:01+00:00 2026-06-14T20:27:01+00:00

I am attempting to create two lists of records from a database in the

  • 0

I am attempting to create two lists of records from a database in the same page like so:

<?php do {   ?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
</tr>
<?php } while ($row = mysql_fetch_assoc($result)); ?>

<?php do {   ?>
<div>
<h1><?php echo $row['name']; ?></h1>
<p><?php echo $row['email']; ?></p>
</div>
<?php } while ($row = mysql_fetch_assoc($result)); ?>

While the first loop works fine, the second time around (creating the div) the do-while loop does not return any data. How should I go about fixing this?

  • 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-14T20:27:02+00:00Added an answer on June 14, 2026 at 8:27 pm

    Insert a mysql_data_seek($result, 0); between the two loops to reset the result so you can read it again.

    Be warned, if the query didn’t return any rows, mysql_data_seek will give you a warning. Check whether there were rows returned before using it.

    Also be warned, your loops are backwards. You need to fetch, then display. 😛 Otherwise, each loop’s first iteration will spit out an empty row. Use while (...) { } rather than do { } while (...).

    (Also be warned, mysql_query is crap. Stop using it. Please. For all our sakes. The mysqli extension does the same thing, can work almost identically, and — unlike mysql — is actively maintained. Plus, when you finally get around to learning to use prepared statements (and you should learn to use prepared statements), mysqli has them.)

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

Sidebar

Related Questions

Im attempting to create a new operator :? on lists, which operates the same
I'm attempting to create a type-agnostic vector in C++ that is distinguished by two
In c++, I am attempting to create an array to store two different datatypes.
I am attempting to create two identical objects in VB6 by assignment statements; something
I am attempting to create a 3-column layout using two text areas. I can
I'm attempting to create two tables with a one-to-many relationship. Here are the schemas
I'm attempting to create a contacts application that has two main entities - person
I'm attempting to create a ragged hierarchy in SSAS 2005. The Category Name and
I'm attempting to create an application that looks much like the Windows 8 Metro
I am attempting to create a JAR based on two separate Java packages. I

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.