Author Topic: Check if there are any results from mysql  (Read 582 times)

0 Members and 1 Guest are viewing this topic.

Offline vicodinTopic starter

  • Enthusiast
  • Posts: 268
  • Gender: Male
  • Eat Em Up
    • View Profile
Check if there are any results from mysql
« on: March 14, 2008, 02:18:24 PM »
What i want to do is check if anything has retrieved from mysql or not. Any help would be appreciated.

Current code:
Code: [Select]
mysql_select_db("mediapil_mkmdata") or die(mysql_error());
$query = "SELECT * FROM products WHERE proid = $prodid";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
echo '

Web Designer: 4Yrs.
PHP:2 Yrs.
MySQL:2Ysr.

Offline rhodesa

  • Staff Alumni
  • Freak!
  • *
  • Posts: 5,241
  • Gender: Male
  • Bold and nosy. I'm famous for that.
    • View Profile
    • VectorLoft.com
Re: Check if there are any results from mysql
« Reply #1 on: March 14, 2008, 02:28:12 PM »
like this?

Code: [Select]
<?php
mysql_select_db
("mediapil_mkmdata") or die(mysql_error());
$query "SELECT * FROM products WHERE proid = $prodid";
$result mysql_query($query) or die(mysql_error());
if(
mysql_num_rows($result)){
  while(
$row mysql_fetch_array($result)){

  }
}else{
  echo 
"No rows found";
}
?>
Aaron Rhodes
Lead Developer

Offline vicodinTopic starter

  • Enthusiast
  • Posts: 268
  • Gender: Male
  • Eat Em Up
    • View Profile
Re: Check if there are any results from mysql
« Reply #2 on: March 14, 2008, 02:38:53 PM »
No its only looking for one thing. If it doesnt find it then i want ti to echo something and if it finds it then echo the product.
Web Designer: 4Yrs.
PHP:2 Yrs.
MySQL:2Ysr.

Offline p2grace

  • Devotee
  • Posts: 1,022
  • Gender: Male
    • View Profile
Re: Check if there are any results from mysql
« Reply #3 on: March 14, 2008, 03:02:54 PM »
Count the results before continuing

Code: [Select]
<?php
$query 
"SELECT * FROM products WHERE proid = $prodid";
$result mysql_query($query) or die(mysql_error());
$num mysql_num_rows($result);
if(
$num 0){ // results found
}else{ // no results found
}
?>

~The best way to have a question answered, is to ask an actual question~

Offline vicodinTopic starter

  • Enthusiast
  • Posts: 268
  • Gender: Male
  • Eat Em Up
    • View Profile
Re: Check if there are any results from mysql
« Reply #4 on: March 14, 2008, 03:54:36 PM »
Thank you worked perfect!
Web Designer: 4Yrs.
PHP:2 Yrs.
MySQL:2Ysr.