Home: General Discussions: General Questions:
Question about Perl



oem7110
New User

Apr 24, 2003, 9:16 PM


Views: 6923
Question about Perl

Could anyone tell me how to check whether following statement containing anything? If it contains nothing, what statement can I use to check it?

while (@row=$sth->fetchrow_array)

Thank you


Paul
Enthusiast

Apr 25, 2003, 2:10 AM


Views: 6922
Re: [oem7110] Question about Perl

Well if your query returned any rows then @rows will always contain something. If your query returned 0 rows then the while loop won't execute.


oem7110
New User

Apr 25, 2003, 7:46 AM


Views: 6917
Re: [Paul] Question about Perl

I would like to check whether following statement contains anything, if it contains nothing, I would like to display a message, such as there is no item available!!, it is the reason I need to check following statements contain anything. Could you give me any suggestion how to write a code to perform following function please?

If @row contain nothing then

display there is no item available!!

else

while (@row=$sth->fetchrow_array)

Thank you


Paul
Enthusiast

Apr 25, 2003, 8:52 AM


Views: 6914
Re: [oem7110] Question about Perl

You can't use @rows for that, try this:

if ($sth->rows) {
...
}
else {
# No results
}


oem7110
New User

Apr 25, 2003, 3:21 PM


Views: 6911
Re: [Paul] Question about Perl


In Reply To
Thank you Smile