Obviously, well, first select it to find out something:
while($row2 = mysql_fetch_array($result)) { ... }
This part looks good, let it look inside the loop:
$myarray = array("id"=>$theid, "name"=>name($id), "text"=>$row2[text]);
There are several points. Probably the most important thing, since inside the loop you overwrite $myarray at each iteration. Instead, you want to add to the array. Let me do this:
$myarray = array();
After that, you can bring it out to prove that it basically works:
var_dump($myarray);
This shows you an array containing all the rows. Then you only need to modify the database query so that it returns fields that are of interest to you.
If you cannot do this with the database, you can also manipulate the array:
$myarray = array(); # initialize the array first! while($row2 = mysql_fetch_array($result)) { $myarray[] = array( "id" => $theid, "name" => name($id), "text" => $row2['text'] ); } var_dump($myarray);
Now the result should look the way you want. To output $myarray :
foreach ($myarray as $number => $row) { echo '<div>Number ', $number, ':<dl>'; foreach ($row as $k => $v) { printf("<dt>%s</dt><dd>%s</dd>\n", $k, htmlspecialchars($v)); } echo '</dl></div>' }
hakre
source share