did my select do anything....?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

did my select do anything....?

Post by chris12295 »

I ran a simple search in a database that decides if a keyword matches a word in a column using PHP. How can i print a message if a result was not found? i dont know how to determine if there was a result or not. please help. here is my code so far:

mysql_connect("localhost");
mysql_select_db("Ads");
$query = "select * from user_Ads where model like '$keywords'";
$result = mysql_query($query);
$number_cols = mysql_num_fields($result);
while ($row = mysql_fetch_row($result)) {
echo "<table border=1>\n";
echo "<tr align=left>\n";
for($i=0;$i<$number_cols;$i++){
echo "<td>";
if(!isset($row[$i])) {
echo "N/A";
}
else {
echo $row[$i];
}
echo "</td>\n";
}
echo "</tr>\n";
}
echo "</table>";
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

$num_rows = mysql_num_rows($result);

echo "Number of rows returned: ".$num_rows;
Post Reply