|
Posted by Mara Guida on 12/20/05 16:32
pauld wrote:
> is there a 'better' way to do it than just let the scriptsort
> it out ?
Yes :)
> I want my results to end up as
>
> results[0] => date,ID,value
> results[1] => date,ID,value
> results[2] => date,ID,value
> etc etc
>
> ( there is probably a better way of resetting the temparray but ive
> not found it !)
see below (*)
> $i=0;
> while ($a2=mysql_fetch_assoc($a1))
> {$temparray=array();
> array_push($temparray,$a2['ID'].$a2['date'],$a2['value']);
> $results[$i] = array($temparray);
> if (isset($temparray)) {reset($temparray);}
> print '<br>'.$i.':';
> print_r($results[$i]).'<br>';
> $i=$i++;
<snip>
Don't do this!
$var++ already increments it just by itself.
You really shouldn't assign that to the same var.
Try this (can you predict the output before running the script?):
<?php
$a = 1;
$a++;
echo $a, "<br/>\n";
echo $a++, "<br>\n";
$b = $a++;
echo $b, "<br>\n";
$c = ++$a;
echo $c, "<br>\n";
?>
(*) how to put the return from the database into the $results array
<?php
// ...
$results = array(); // initialize $results
while ($a2 = mysql_fetch_assoc($a1)) {
// this construct adds an element to the $results array
$results[] = array($a2['date'], $a2['ID'], $a2['value']);
}
// DEBUGGING
echo '<pre>'; print_r($results); echo '</pre>';
// ...
?>
Navigation:
[Reply to this message]
|