0

I am struggling to echo an error message stating 'No results' when my mysql query returns nothing. I am using PEAR. Here is what I have at the moment.

while($rows =& $output->fetchRow()) {
if (numRows($query)== 0){
   echo 'No results';
}
else {
 echo 'data found';
}

}

Any help will be greatly appreciated, thanks for checking out my question.

Daniel Mabinko
  • 1,351
  • 3
  • 11
  • 10

1 Answers1

2

If there are no results, fetchRow won't return anything, which means the loop doesn't get executed at all, which means the code inside the loop won't either. The logic is:

if numRows == 0
    echo error
else
    while fetchRow
        echo result
deceze
  • 510,633
  • 85
  • 743
  • 889
  • Ok thanks for your response. I have tried this logic and cant get it to work. Could you help me out please? – Daniel Mabinko Apr 24 '12 at 02:00
  • Please update your question with more code then if you require an answer with actual code. It's hard to guess what's what from the small snippet you're showing. – deceze Apr 24 '12 at 02:05