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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:42:35+00:00 2026-05-28T03:42:35+00:00

this one is really puzzling me, so thanks for any help. I am trying

  • 0

this one is really puzzling me, so thanks for any help. I am trying to output the values of a SQL result set, but the foreach loop appears to be iterating twice, then incrementing the array index. Such that if my DB row holds the contiguous integers 1,2,3,4,5 the output of the foreach loop is 1,1,2,2,3,3,4,4,5,5. Can’t see the reason. Code follows.

$result = mysql_query("SELECT * FROM Test");

echo "<table border=1><tr></tr>";

While($row = mysql_fetch_array($result))
{
    echo "<tr>";
    foreach($row as $value)
    {
        echo "<td>" . $value . "</td>";
    }
    echo "</tr><tr>";
    for($x=0;$x<5;$x++)
    {
        echo "<td>" . $row[$x] . "</td>";
    }
    echo "</tr>";
}

The second for loop was thrown in afterwards for debugging, to make sure the array didn’t actually contain two instances of each value. But that loop outputs as expected: 1,2,3,4,5. Any Ideas? Thanks.

  • 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-28T03:42:36+00:00Added an answer on May 28, 2026 at 3:42 am

    By default, mysql_fetch_array‘s second parameter is set to MYSQL_FETCH_BOTH, which will register each value under the index as well as the name of the column. Supply MYSQL_FETCH_NUM to get only numeric indices:

    while($row = mysql_fetch_array($result, MYSQL_FETCH_NUM)) {
     ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this one is really easy. I'm trying to create a Regular Expression that will
I really need help on this one. I am having a simple login form
Hey, I'm really struggling with this one. I'am trying to port a small piece
I have started playing around with Berkeley DB. This one is really interesting, but
This one's really getting me down! :( I'm trying to make a nested model
This one is really weird. I have multiple $.post() in the code, but there
IE6 is always surprising me but this one is REALLY odd. I'm creating a
I'm really puzzled by this one!! I'm sure it's simple but really can't figure
Boy, this one is really weird. I expect the following code to print 1990,
Ok, this one is really weird... I can't show code for it exactly cause

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.