PHP > seems to be closing my PHP tag?

noBull

New member
Code:
<html>
<head>
<basefont face="Arial">
</head>
<body>

<?php

// set server access variables
$host = "localhost";
$user = "HANJER59";
$pass = "k2032K";
$db = "testdb";

// open connection
$connection = mysqli_connect($host, $user, $pass, $db) or die ("Unable to connect!");

// create query
$query = "SELECT * FROM symbols";

// execute query
$result = mysqli_query($connection, $query) or die ("Error in query: $query. ".mysqli_error());


if (mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_row($result)) {
        echo "<td>".$row[0]."</td>";
        echo "<td>".$row[1]."</td>";
        echo "<td>".$row[2]."</td>";
    }
}

// free result set memory
mysqli_free_result($result);

// close connection
mysqli_close($connection);

?>

</body>
</html>


The output looks like this:

0) { while($row = mysql_fetch_row($result)) { echo "".$row[0].""; echo "".$row[1].""; echo "".$row[2].""; } } // free result set memory mysqli_free_result($result); // close connection mysqli_close($connection); ?>

That is all that shows up on the page when opened in a browser. Cutting off at the > in the if statement, which made me assume it is closing my PHP statement. What am I doing wrong here?
By index I am assuming you mean the table data.

It is done in PHPMyAdmin. This is the SQL code used to create the DB and table.

CREATE DATABASE testdb;

CREATE TABLE `symbols` (
`id` int(11) NOT NULL auto_increment,
`country` varchar(255) NOT NULL default '',
`animal` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;

INSERT INTO `symbols` VALUES (1, 'America', 'eagle');
INSERT INTO `symbols` VALUES (2, 'China', 'dragon');
INSERT INTO `symbols` VALUES (3, 'England', 'lion');
INSERT INTO `symbols` VALUES (4, 'India', 'tiger');
INSERT INTO `symbols` VALUES (5, 'Australia', 'kangaroo');
INSERT INTO `symbols` VALUES (6, 'Norway', 'elk');

a table with 3 columns and 6 data entries.
I did try what you said, and changed it to:

" if (0 < mysql_num_rows($result)) "

and got a slightly different, but equally confusing result:

".$row[0].""; echo "".$row[1].""; echo "".$row[2].""; } } // free result set memory mysqli_free_result($result); // close connection mysqli_close($connection); ?>
 
Back
Top