contra10 Posted February 19, 2009 Share Posted February 19, 2009 i'm trying to say no results have occured if there is no match to a search my coding is <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //This code runs if the form has been submitted if(isset($_POST['submit']) and ($_POST['country'])) { $postuser = "{$_POST['username']}"; $postcountry = "{$_POST['country']}"; $postfemale = "{$_POST['sexf']}"; $postcountry = "{$_POST['country']}"; $postage1 = "{$_POST['age1']}"; $postage2 = "{$_POST['age2']}"; $query = "SELECT * FROM users WHERE country='$postcountry'"; if(isset($_POST['username']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `username` = '$postuser' ";} if(isset($_POST['sexf']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `sex` = '$postfemale' ";} if(isset($_POST['sexm']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `sex` = 'male' ";} if(isset($_POST['age1']) and ($_POST['age2']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `age` BETWEEN '$postage1' and '$postage2'";} $result = mysql_query($query); if($result){ while ($row = mysql_fetch_assoc($result)){ $user = "{$row['id']}"; $userq = "{$row['username']}"; $mycountry = "{$row['country']}"; $sex = "{$row['sex']}"; $city = "{$row['city']}"; echo "<tr>"; echo "<td width='20%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' color='#0094f7' SIZE='2'>$userq<br>"; echo "<img src='http://localhost/image/imagereplace.php?id=$user'><br>"; echo "$city, $mycountry $sex</a></FONT></td>"; echo "<td width='60%'></td>"; echo"<td width='30%' align='right' valign='top'><a style='text-decoration:none' href='http://localhost/friendrequest/index.php?user=$user'>"; echo "<FONT FACE='ariel' SIZE='2' color='#0094f7' align='center'><b>Add as Friend</b><br></font></a>"; echo "<a style='text-decoration:none' href='http://localhost/inbox/sendmessage.php?id=$user'>"; echo "<FONT FACE='ariel' SIZE='2' color='#0094f7' align='center'><b> Send Message</b></Font></a>"; echo "</td></tr>"; } }else{ echo"no results"; } } ?> how can i echo "no results" if there is no match Quote Link to comment Share on other sites More sharing options...
xstevey_bx Posted February 19, 2009 Share Posted February 19, 2009 add just after the query $num = mysql_num_rows($result); and if there is a result then $num will = 1 or more so then run an if statement if($num >= 1) { echo 'show the profile'; } else { echo 'no results were found'; } Quote Link to comment Share on other sites More sharing options...
contra10 Posted February 19, 2009 Author Share Posted February 19, 2009 thnks <?php $result = mysql_query($query); $num = mysql_num_rows($result); if($num >= 1) { while ($row = mysql_fetch_assoc($result)){ ?> Quote Link to comment Share on other sites More sharing options...
xstevey_bx Posted February 19, 2009 Share Posted February 19, 2009 haha nice to know I could help someone for a change!! =D Quote Link to comment 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.