martin729 Posted October 23, 2009 Share Posted October 23, 2009 hey all, I have a lil mysql/php/apache script that queries a database and pulls put 5 integers. These 5 integers are then displayed in an HTML table <?php $i=0; global $Val_Store; while ($i < $num) { $f1=mysql_result($result,$i,"Changes"); $f2=mysql_result($result,$i,"Disposition"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> </tr> <?php $Val_Store[i] = $f1; $i++; echo $Val_Store[i] . "-> Val_STORE" . $i . "<br />"; } This is just a snippet. But what is happening is: A while loop is going through the rows of results obtained from the query, placing the values in temporary variables f1 and f2 (f1 are my integers of interest), and using f1 and f2 to fill the HTML table like this: <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> BUT what i am also doing is storing the temporary values in f1 in the array $Val_Store $Val_Store[i] = $f1; $i++; And then printing them .... echo $Val_Store[i] . "-> Val_STORE" . $i . "<br />"; Leaving me with 84-> Val_STORE1 114-> Val_STORE2 99-> Val_STORE3 77-> Val_STORE4 5-> Val_STORE5 WHICH IS SUPER! BUT if i try executing the following code in other sections of my script.... <? echo "DEBUG " . $Val_Store[2] . " DEBUG"; ?> ...the arrays appears to be empty. Surely it should have spat out element number 2!! Output: DEBUG DEBUG ^ Can anyone help me keep my array elements?? Many Thanks Martin Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 23, 2009 Share Posted October 23, 2009 Hi You need an extra $ sign in a few places. Eg:- $Val_Store[$i] = $f1; All the best Keith Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted October 23, 2009 Share Posted October 23, 2009 echo "DEBUG " . $Val_Store[2] . " DEBUG"; actually that would spit out the 3rd element. Arrays start with zero. you could do print_r($Val_Store); that will give you a better idea of what's in the array. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.