#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    singapore
    Posts
    21
    Rep Power
    0
    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. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Southern California
    Posts
    73
    Rep Power
    15
    <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.


IMN logo majestic logo threadwatch logo seochat tools logo