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 |
-----------------------------------------------
You are sort of missing the point of
mysql_fetch_assoc()and rows in MySQL: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):