Forum Moderators: coopster
<?
// 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.
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" ){