Posted by glenn on 02/24/07 11:45
I am try to teach myself PHP and MYSQL.
Below I have a php file I have created which when i look at it in a browser
returns a nice list of people and there addresses.
When I change the $data line from
$data = mysql_query("SELECT * FROM dir ORDER BY SURNAME") or
die(mysql_error());
to
$data = mysql_query("SELECT * FROM dir WHERE SURNAME = 'SMITH'") or
die(mysql_error());
I expected my page to show all the people who had the surname SMITH. But
instead I get nothing.
When I run the query SELECT * FROM dir WHERE SURNAME = 'SMITH';
against my mysql databse it returns the lines with SURNAME Smith.
Can anyone tell me why it doesnt work in my php file?
<html>
<head>
<title></title>
</head>
<body>
<font size="2" face="Century Gothic" color="#0000FF">
<?php
//Connect information
mysql_connect("localhost", "gaspa", "blah123") or die (mysql_error());
mysql_select_db("SBC") or die (mysql_error());
// Collects data from "dir" table
$data = mysql_query("SELECT * FROM dir ORDER BY SURNAME") or
die(mysql_error());
// puts the "dir" info into the $info array
$info = mysql_fetch_array( $data );
// Print out the contents of the entry
while($info = mysql_fetch_array( $data ))
{
Print "<b>SURNAME:</b> ".$info['SURNAME'] . " ";
Print "<b>HOME PHONE:</b> ".$info['HOME_PHONE'] . " ";
Print "<b>Name:</b> ".$info['NAME_1'] . " ";
Print "<b>Mob:</b> ".$info['PHONE_1'] . " ";
Print "<b>Birthday:</b> ".$info['BIRTHDAY_1'] . " ";
Print "<b>Name:</b> ".$info['NAME_2'] . " ";
Print "<b>Mob:</b> ".$info['PHONE_2'] . " ";
Print "<b>Birthday:</b> ".$info['BIRTHDAY_2'] . "<br><Br> ";
}
Print "</table>";
?>
</font>
</strong>
</body>
</html>
[Back to original message]
|