suttercain Posted September 7, 2007 Share Posted September 7, 2007 Hi everyone, I have a basic search set up here: http://72.167.22.157/search.html But for some reason I cannot get a simple section to work. Try the above link and search the term 'hil' When you get the results you'll see an address and Contact. My problem is I don't want the word contacts to show up if there are no contacts. I cannot get this to work. When I checked mysql_num_row it says 1 on every result, even if there is no contact... <?php if (isset($_POST['submit'])) { // If the Submit button was pressed. if (isset($_POST['search'])) { //If there is data iun the search form. $search = trim($_POST['search']); //Trim whitespace. $result = mysql_real_escape_string($search); // Secure the data. $sql = mysql_query("SELECT DISTINCT FirmName, Address, City, State, PostalCode FROM membership WHERE FirmName LIKE '%".$result."%' ORDER BY FirmName") or die(mysql_error()); $total = mysql_num_rows($sql); while ($row = mysql_fetch_assoc($sql)) { echo "<fieldset>"; echo "<legend>" . $row['FirmName'] . "</legend>"; echo "<b>Address:</b><br />"; echo $row['Address']; echo "<br />"; echo $row['City'] . ", " . $row['State'] . " " . $row['PostalCode'] . ""; if ($total > 0) { $results = mysql_query("SELECT * FROM membership WHERE FirmName = '".$row['FirmName']."' AND Address = '".$row['Address']. "' AND PostalCode = '".$row['PostalCode']. "' ORDER BY principal DESC") or die(mysql_error()); //$tot = mysql_num_rows($results); echo "<br />"; echo "<br />"; echo "<b>Contacts:</b><br />"; //Only want this to show if there is at least 1 result while ($name = mysql_fetch_array($results)) { $principal = ($name['principal'] == 1) ? " - Principal" : ""; echo $name['FirstName'] . " " . $name['LastName'] . "$principal"; echo "<br />"; } } echo "</fieldset>"; echo "<br />"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68432-wtf/ Share on other sites More sharing options...
darkfreaks Posted September 8, 2007 Share Posted September 8, 2007 <?php $row = mysql_num_rows($result); if ($row['contacts']<1) { die ("Sorry but the searched turned up nothing"); } else if ($row['contacts']>1) { echo "$row['contacts']"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68432-wtf/#findComment-344088 Share on other sites More sharing options...
suttercain Posted September 8, 2007 Author Share Posted September 8, 2007 From my first post "When I checked mysql_num_row it says 1 on every result, even if there is no contact..." Quote Link to comment https://forums.phpfreaks.com/topic/68432-wtf/#findComment-344125 Share on other sites More sharing options...
marcus Posted September 8, 2007 Share Posted September 8, 2007 //uncomment the $tot if($tot >= 1){ //show contacts }else { //no contacts } Quote Link to comment https://forums.phpfreaks.com/topic/68432-wtf/#findComment-344126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.