Jump to content

[SOLVED] state a sentence if query is false


contra10

Recommended Posts

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.