Forum Moderators: coopster

Message Too Old, No Replies

displaying mysql problem

         

smatts9

10:31 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



I'mfairly new to Mysql and need help figuring this out

<?
// listing script

// connect to the server
mysql_connect( 'localhost', 'user', 'pass' )
or die( "Error! Could not connect to database: " . mysql_error() );

// select the database
mysql_select_db( 'user_db' )
or die( "Error! Could not select the database: " . mysql_error() );

// retrieve all the rows from the database
$query = "SELECT * FROM db ORDER BY name";

$results = mysql_query( $query );

// print out the results
if( $results )
{
while( $db = mysql_fetch_object( $results ) )
{
// print out the info
$id = $db -> id;
$name = $db -> name;
$city = $db -> city;
if( $city == Baltimore ){

echo( "<a href='detail.php?id=$id'>$name<br></a>" );
}
else
{

die( "Trouble getting contacts from database: " . mysql_error() );
}
?>

I am trying to display the tables that only have their city = to the one given, and it wont work?... I cant seem to figure this one out. Thanks for your help.

Dijkgraaf

10:57 pm on Feb 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For starters, why don't you have the following?
$query = "SELECT * FROM db WHERE city='Balitmore' ORDER BY name";

This way your query will only return those records you are interested in

Also your if statement
if( $city == Baltimore ){
Shouldn't that have quotes around Baltimore?
e.g.
if( $city == "Baltimore" ){