| |||||||||||
Loop Problem Posted by Chris_Isaac (Chris Isaac), 29 January 2004 HiThe bit of script below should after a query to a db, either print "no matches" or print the matches out. It prints out any matches that are there, but doesn't print "no matches" if none are found, can anyone see anything obvious that is wrong? Code:
I've also tried changing the if (count($row)=="") to a 0 but that didn't work either. I did get it close by using the following: Code:
That does print out "no Matches", but also prints "no Matches" to the end of the query if some are found. Any ideas? Posted by admin (Graham Ellis), 29 January 2004 If there are no matches, you'll never get into the loop - remember that a while loop runs ZERO or more times, and if there's no match yours runs zero times - i.e. ignores all the code within the loop.Here's the sort of thing I might write ... Code:
Posted by Chris_Isaac (Chris Isaac), 29 January 2004 Excellent, thats done it, thank you.Out of curiosity, is there a way of checking if an array is empty and testing against that? I thought something like if(count($myArray)==0) {..... would be actioned if there were no elements in the array, but it didn't work, should it have? Posted by admin (Graham Ellis), 29 January 2004 At first glance, I would have expected that test to work ... if it continues to give trouble, print out the contents of the $myArray variable before the test, and also print something out within the conditional block. That way, you should be pointed to where to look further for what's not functioning rightPosted by Chris_Isaac (Chris Isaac), 29 January 2004 I thought it would work too, nevermind, got around it now anyway, but thanks for the response.This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |