PHP Newsletter

Join now and receive weekly updates pertianing to the world of PHP.

Polls

What do you think about the new PHPMine Design?
Awesome
Not Bad
Sucks

PHP Gigs By City

PHP Jobs By Topic

Advertisements

PHP > seems to be closing my PHP tag?

Asked 2010-03-11 16:47:37 by noBull

[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>

[/code]


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); ?>

Anwered 2010-03-11 17:41:16 by Michael

When you open the page in a browser are you looking at it locally as an html file, in which case everything between <? and > will be treated as an unknown tag, or are viewing it having been served up by a php enabled webserver?

Have you considered rewriting:

if (mysql_num_rows($result) > 0)

as:

if (0 < mysql_num_rows($result))

Which is equivalent but uses a different character for the comparison.

Anwered 2010-03-11 16:50:51 by voshii

Hi, noBull

please put the main index as well to investigate the issue
it is just an output
also yourweb-serverr may not beconfiguredd well

thank you

Questions and answers provided by the Yahoo Answers Community.