fcruz5
asked on
Table Row Results
Hi,
I have two table rows that display data. The first table row displays several results. The second table row should only display one result. But it is repeating itself. It displays the same amount of results as the first table row. So if the the first table row displays 10 results then the second table row will display 10 results.
But since the second table row only has one result, then it repeats itself.
How can I make it only appear once? Would I have to add its own separate mysql query on the second "foreach" line?
The code is below:
<?php
if($result && mysql_num_rows($result) > 0)
{ for ($i = 0; $i < mysql_num_rows($result); $i++) {
$resultArray[$i] = mysql_fetch_array($result) ;
}
foreach ($resultArray as $val) {
echo ('<tr>');//first row
echo ('<td>'.$val[1].'</td>');
echo ('<td>'.$val[2].'</td>');
echo ('<td>'.$val[3].'</td>');
echo ('</tr>');
}
foreach ($resultArray as $val) {
echo ('<tr>');//second row
echo ('<td>'.$val[4].'</td>');
echo ('<td>'.$val[5].'</td>');
echo ('<td>'.$val[6].'</td>');
echo ('</tr>');
}
} // end if results
echo ('</table>');
?>
I have two table rows that display data. The first table row displays several results. The second table row should only display one result. But it is repeating itself. It displays the same amount of results as the first table row. So if the the first table row displays 10 results then the second table row will display 10 results.
But since the second table row only has one result, then it repeats itself.
How can I make it only appear once? Would I have to add its own separate mysql query on the second "foreach" line?
The code is below:
<?php
if($result && mysql_num_rows($result) > 0)
{ for ($i = 0; $i < mysql_num_rows($result); $i++) {
$resultArray[$i] = mysql_fetch_array($result)
}
foreach ($resultArray as $val) {
echo ('<tr>');//first row
echo ('<td>'.$val[1].'</td>');
echo ('<td>'.$val[2].'</td>');
echo ('<td>'.$val[3].'</td>');
echo ('</tr>');
}
foreach ($resultArray as $val) {
echo ('<tr>');//second row
echo ('<td>'.$val[4].'</td>');
echo ('<td>'.$val[5].'</td>');
echo ('<td>'.$val[6].'</td>');
echo ('</tr>');
}
} // end if results
echo ('</table>');
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The second one did the trick. Thanks!
<?php
if($result && mysql_num_rows($result) > 0)
{ for ($i = 0; $i < mysql_num_rows($result); $i++) {
$resultArray[$i] = mysql_fetch_array($result)
}
foreach ($resultArray as $val) {
echo ('<tr>');//first row
echo ('<td>'.$val[1].'</td>');
echo ('<td>'.$val[2].'</td>');
echo ('<td>'.$val[3].'</td>');
echo ('</tr>');
}
foreach ($resultArray as $val) {
echo ('<tr>');//second row
echo ('<td>'.$val[4].'</td>');
echo ('<td>'.$val[5].'</td>');
echo ('<td>'.$val[6].'</td>');
echo ('</tr>');
break;
}
} // end if results
echo ('</table>');
?>