PDA

View Full Version : Help with PHP and mysql code.



BillyHoppe14843
January 1st, 2011, 01:31 AM
I am working with PHP and mysql and need some help in figureing out the code to select data from a data base by states and it needs to display a message when there is no listing for that state. My email is bghoppe@stny.rr.com, my aim is billyghoppe@aim.com, thank you for your time in this matter.

Billy Hoppe.

muaaz007
January 1st, 2011, 02:52 PM
It is simple what i understand what you wrote

<?php
$sql = "Select * from states where `statename` = `PostedStateName`; ";
$rs = mysql_query($sql);
$row = mysql_fetch_array($rs);
if($row == NULL)
echo "No Data in State"
//Display the names
?>

epicoder
January 3rd, 2011, 02:25 AM
A couple of syntax corrections to muaaz007's otherwise correct solution:


<?php
$sql = "Select * from states where `statename` = `PostedStateName`"; // mysql_query doesn't need a semicolon on the end of the query.
$rs = mysql_query($sql);
$row = mysql_fetch_array($rs);
if($row == NULL) {
echo "No Data in State"
} else {
//Display the names
}
?>

@OP: Generally it's not a good idea to post your email address openly on a site. You'll get a ton of spam.