|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Anyone know wat's the statement for checking if the table is empty using perl DBI. Will there be any results if the table is empty if i execute this? A simple example of my program..
$sth = $dbh->prepare("select * from testing"); $sth->execute; while(@row = $sth->fetchrow_array) { if (row[0] == "") { print "No data"; } else { #display data } } After trying the above program..nothing is displayed. In my case the table is empty so it should display the message "No data". |
|
#2
|
||||
|
||||
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by sEnG:
[B]After trying the above program..nothing is displayed. In my case the table is empty so it should display the message "No data[/B/[/quote] The WHILE loop only executes while its condition is true. Since the assignment to row is not defined, it evaluates to false and the code within its block is not executed. You should change the WHILE to an IF: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> if (@row = $sth->fetchrow_array) { # display data } else { print "No data.n"; } [/code] Hope this helps. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Check if table is empty?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|