I have several tables that may or may not contain data at any given time. I need to query eatable to see if a $userid resides in each table. I have a loop that queries each table for the $userid varable. It may be that there is no data in one or more tables but I need to know if that is the case then I can wriote to the browser that the $userid was not found in that table then e loop goes on to to the next table which may have the $userid in it which would then tell the user he is in that particular table. But for some reason if the table is empty and the query return has nothing in it I cant test for the $userid; it gives me nothing. Here is the code I am using:
#======================= [ open_dbi ] ======================= my $sql = "SELECT * FROM $course"; my $query=$dbh->prepare("$sql") or die "Couldn't prepare statement: " . $dbh->errstr; if (defined($query)) { $query->execute(); ###################################################################### +######### while (@row=$query->fetchrow_array()) { foreach ($row[0]) { print "$course"; if ($row[0] eq $userid) { print "$userid you are registered for this course $course<BR>" +; }elsif ($row[0]) {print "$course";} } } ###################################################################### +######### $dbh->disconnect;
(The variable $course is brought in from another db search.) The code above fails to execute the else statement if there is no data in the table, if there is data the code works. Ive tried everything I can think of. I need to be able to tell the student that he is registered this course but not for these.

In reply to testing for retuning value of DBI querry is empty by demonlazeros

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.