problem in my php code
Hongwei Li
hongwei at wustl.edu
Wed Nov 17 15:10:11 UTC 2004
Hi,
I have a problem in my php code. I simplify the code as the 4 pieces
below and hope somebody can help me to fix the problem.
1. tsstart.php: -- this is the start point to be browsed
<?php
include "tsdata.php";
include "tsshow.php";
?>
2. tsdata.php: -- to get data, here I set it as a 2-d array and assign
values to it to simplify the code
<?php
global $obj;
global $ind;
for($i=0;$i<3;$i++) {
for($j=0;$j<3;$j++) {
$obj[$i][$j] = $i + $j*2;
}
}
$ind=0;
?>
3. tsshow.php: -- display the values of $obj:
<?php
global $obj;
global $ind;
echo "result-set index: " . $ind . "<br>";
?>
<html> <body>
<table align=center>
<tr><td>First Row:</td><td><? echo $obj[$ind][0] ?></td> </tr>
<tr><td>Second Row:</td><td><? echo $obj[$ind][1] ?></td> </tr>
</table>
<a href="tsnext.php">Next</a>
</body> </html>
4. tsnext.php: -- to display the next 2-d array element's value:
<?php
global $obj;
global $ind;
$ind++;
echo "new ind: " . $ind . "<br>";
include "tsshow.php";
?>
Now, when I browse tsstart.php, it displays:
result-set index: 0
First Row: 0
Second Row: 2
and the link "Next"
However, when I click the link "Next", it displays:
new ind: 1
result-set index: 1
First Row:
Second Row:
no values are displayed. Apparently, $obj is not passed to tsnext.php and
tsshow.php (the second time), but $ind is. What is wrong in the above
codes? Can somebody help me?
I greatly appreciate all help!
Hongwei Li
More information about the fedora-list
mailing list