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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:52:28+00:00 2026-05-26T20:52:28+00:00

After query I try to display data. I can receive only data from ‘field_1[]’.

  • 0

After query I try to display data. I can receive only data from ‘field_1[]’. From ‘field_2[]’ and from ‘field[]’ no. How to fix it?

if (!$result) {    
die("Query to show fields from table failed");
}

$fields_num = mysql_num_rows($result);

//------------------------------------------------------------------    
for($i_1=0; $i_1<$fields_num; $i_1++)
{    
$field_1 = mysql_fetch_assoc($result);    
echo "<td>a".$field_1['index_period_1']."</td>";
}
//------------------------------------------------------------------
//------------------------------------------------------------------

for($i=0; $i<$fields_num; $i++)
{    
$field = mysql_fetch_assoc($result);    
echo "<td>b".$field['index_period']."</td>";
}
//------------------------------------------------------------------
//------------------------------------------------------------------    
for($i_2=0; $i_2<$fields_num; $i_2++)
{    
$field_2 = mysql_fetch_assoc($result);    
echo "<td>c".$field_2['index_period_2']."</td>";
}

edit:———————-

|------------|period_1  |period_1  |period_1  |
-----------------------------------------------
|period_2    |period    |period    |period    |
-----------------------------------------------
|period_2    |period    |period    |period    |
-----------------------------------------------
  • 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-26T20:52:29+00:00Added an answer on May 26, 2026 at 8:52 pm

    You are sort of missing the point of mysql_fetch_assoc() and rows in MySQL:

    while ($row = mysql_fetch_assoc($result)) {
      echo $row['index_period'];
      echo $row['index_period_1'];
      echo $row['index_period_2'];
    }
    

    You call mysql_fetch_assoc() once per row.


    I’m not really sure why you need to loop over your table like this, but I won’t interrogate you.

    This might fit your needs (I cringe writing this):

    $index_period = array();
    $index_period_1 = array();
    $index_period_2 = array();
    
    while ($row = mysql_fetch_assoc($result)) {
      $index_period[] = $row['index_period'];
      $index_period_1[] = $row['index_period_1'];
      $index_period_2[] = $row['index_period_2'];
    }
    
    foreach ($index_period as $value) {
      echo "<td>a" . $value . "</td>";
    }
    
    foreach ($index_period_1 as $value) {
      echo "<td>b" . $value . "</td>";
    }
    
    foreach ($index_period_2 as $value) {
      echo "<td>c" . $value . "</td>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I type 'from' (in a LINQ query) after importing System.Linq namespace , it
How can I view the SQL code of my query after it has been
I have a query that is dynamically built after looking up a field list
What ia m trying to do is display a success message after the query
I'm using the following mysql query to return some data from my database. Currently
I try this query from Oracle : select * from a_table@Postgres; Here is the
Is there any reason why I should close the connection after a query or
How do I view the warning(s) after a SELECT query? The result of one
After running a insert or update query against a SQLServer 2005 database, under what
After trying to avoid JavaScript for years, Iv started using Query for validation in

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.