Strange result using current and next
Posted: Sun Jul 13, 2008 2:07 pm
Please help me understand what I am doing wrong with use of current and next.
I created the following MySQL database for purpose of demonstration:
CREATE DATABASE `Test` ;
CREATE TABLE `Tble` (
`Field1` TEXT NOT NULL ,
`Field2` TEXT NOT NULL ,
`Field3` TEXT NOT NULL
) ENGINE = MYISAM ;
INSERT INTO `Test`.`Tble` (
`Field1` ,
`Field2` ,
`Field3`
)
VALUES (
'One', 'Two', 'Three'
);
Then I created the following module (TestOneTwoThree.php) to demonstrate the result I am experiencing:
<html>
<?php
error_reporting(E_ALL);
$host = "localhost";
$user = "Roger";
$password = "xxxxxx";
$connection = mysql_connect($host, $user, $password)
or die(mysql_error() . "<br>");
$dbname = "Test";
mysql_select_db($dbname)
or die(mysql_error());
$sql = "SELECT * FROM Tble" ;
$result = mysql_query($sql)
or die(mysql_error() . "<br>");
$row = mysql_fetch_array($result);
$cell = current($row);
echo $cell;
$cell = next($row);
echo $cell
$cell = next($row);
echo $cell;
$cell = next($row);
echo $cell
$cell = next($row);
echo $cell;
$cell = next($row);
echo $cell;
?>
</html>
And, this is the resulting display:
OneOneTwoTwoThreeThree
What am I doing wrong in my use of current and next?
Thanks,
Roger
I created the following MySQL database for purpose of demonstration:
CREATE DATABASE `Test` ;
CREATE TABLE `Tble` (
`Field1` TEXT NOT NULL ,
`Field2` TEXT NOT NULL ,
`Field3` TEXT NOT NULL
) ENGINE = MYISAM ;
INSERT INTO `Test`.`Tble` (
`Field1` ,
`Field2` ,
`Field3`
)
VALUES (
'One', 'Two', 'Three'
);
Then I created the following module (TestOneTwoThree.php) to demonstrate the result I am experiencing:
<html>
<?php
error_reporting(E_ALL);
$host = "localhost";
$user = "Roger";
$password = "xxxxxx";
$connection = mysql_connect($host, $user, $password)
or die(mysql_error() . "<br>");
$dbname = "Test";
mysql_select_db($dbname)
or die(mysql_error());
$sql = "SELECT * FROM Tble" ;
$result = mysql_query($sql)
or die(mysql_error() . "<br>");
$row = mysql_fetch_array($result);
$cell = current($row);
echo $cell;
$cell = next($row);
echo $cell
$cell = next($row);
echo $cell;
$cell = next($row);
echo $cell
$cell = next($row);
echo $cell;
$cell = next($row);
echo $cell;
?>
</html>
And, this is the resulting display:
OneOneTwoTwoThreeThree
What am I doing wrong in my use of current and next?
Thanks,
Roger