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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:05:46+00:00 2026-05-25T03:05:46+00:00

I have the following code: $result = mysql_query(SELECT * FROM events,$db); $rowcheck = mysql_num_rows($result);

  • 0

I have the following code:

$result = mysql_query("SELECT * FROM events",$db);
$rowcheck = mysql_num_rows($result);
    $allevents = array();
    echo "<br>Display events: ($rowcheck)";
    $i = '0';
while ($row_user = mysql_fetch_assoc($result)){
    $allevents[] = $row_user;

    foreach ($allevents as $val) {
        $eventID = $val['event_ID'];

        echo "<br>$eventID";

        echo "End foreach.";
    }  // end foreach events as val


    echo "End While.";
} // end while
print_r($allevents);

And get the following output:

Display events: (3)  
ID 1 End foreach.End While.  
ID 1 End foreach.  
ID 2 End foreach.End While.  
ID 1 End foreach.  
ID 2 End foreach.  
ID 3 End foreach.End While. 
Array (   
 [0] => Array (  
   [event_ID] => 1  
   [eventtype] => 1  
   [eventlocation] => 1  
   [eventhostfamily] => 23  
   [eventturn] => 459  
   [char1] => 9  
   [char2] => 19 
 )  
 [1] => Array (  
   [event_ID] => 2  
   [eventtype] => 4  
   [eventlocation] => 1  
   [eventhostfamily] => 29  
   [eventturn] => 461  
   [char1] => 208  
   [char2] => 0 
 )  
 [2] => Array (  
   [event_ID] => 3  
   [eventtype] => 4  
   [eventlocation] => 1  
   [eventhostfamily] => 28  
   [eventturn] => 462  
   [char1] => 1  
   [char2] => 0 
 ) 
)

For some reason that I cannot fathom, its giving me some weird loop where it returns the 1st row, then the first two rows, then the first three rows.

What am I doing 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-05-25T03:05:46+00:00Added an answer on May 25, 2026 at 3:05 am

    You are appending each row from mysql to your array and then output the whole array. Move the foreach loop out of your while:

    while ($row_user = mysql_fetch_assoc($result)){
        $allevents[] = $row_user;
        echo "End While.";
    } // end while
    
    foreach ($allevents as $val) {
        $eventID = $val['event_ID'];
    
        echo "<br>$eventID";
    
        echo "End foreach.";
    }  // end foreach events as val
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

.i have the following code: $task_id = mysql_query(SELECT MAX(task_id) from it_task); echo $task_id; .what
Ok, I have the following code: $array = mysql_query(SELECT artist FROM directory WHERE artist
I have the following code: (query added) $weight_table = mysql_query (SELECT * FROM .$prefix.weight
I have the following code: $sql = mysql_query(SELECT id FROM logins WHERE id=' .
I have the following code: $mostRecent = mysql_query(SELECT couponID FROM users_coupons WHERE userID =
I have the following (simplified) result from SELECT * FROM table ORDER BY tick,refid
I have the following PHP/MySQL code: function executeMultirowQuery($query) { $result = mysql_query($query); $table =
i have the following code for search from database show return result to the
I have the following code in action script 3: async.addResponder(new Responder(result, defaultFaultHandler)); result is
I have the following code : std::string Utils::get() { std::string result; result.append(1, 'x'); result.append(1,

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.