I'm new to web programming and extra new to PHP/MySQL, and I just got my first page up and running. It works OK, but I'd like to display:
"Please select search criteria"
before the query, then
"Sorry no records matched your search criteria"
if no hits in the database.
I'm sure this is very elementary, but I'd appreciate the help. Here's the code:
<?php
mysql_connect (localhost,gowestca_user,xxxxx);
mysql_select_db (gowestca_properties);
$result = mysql_query("SELECT *
FROM properties
WHERE prop_beds = '$beds'
AND prop_price <= '$price'
") //this query takes form data and searches DB for matches
or die(mysql_error()); //just in case something goes goofy
if ($row = mysql_fetch_array($result)) { //check for query hits
do { //display query results in table
?>
<tr>
<td class="regText" height="14"><?php print $row["prop_name"]?></td>
<td class="regText" height="14"><?php print $row["prop_beds"]?></td>
<td class="regText" height="14"><?php print $row["prop_baths"]?></td>
<td class="regText" height="14">$<?php print $row["prop_price"]?></td>
<td class="regText" height="14"><?php print $row["prop_type"]?></td>
<td class="regText" height="14"><?php print $row["prop_url"];?></td>
</tr>
<?php
}
while($row = mysql_fetch_array($result));?>
</table>
<?php
} else {?>
<td class="regText" height="14"><?php print "Sorry no records match your criteria.";?></td>
<?php } //print message if no matching records ?>
Sorry for the sloppy coding. Thanks for your help.