By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,303 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,303 IT Pros & Developers. It's quick & easy.

new to php and mysql and need a little help

P: n/a
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>


Feb 24 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Feb 24, 5:45 am, "glenn" <g...@bigpond.comwrote:
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>
take out the first mysql_fetch_array line
Craig

Feb 24 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.