I have written a Perl script to schedule appointments at a clinic. The code puts clients in timeslots for every clinic day. There is a MySQL query that simply gets the nurse names and IDs then makes a drop-down select button beside the client's names in the schedule. When there is more than 9 people scheduled for the day the query hangs the script. It also hangs if there are more that 3 people with the same appointment time and more than 5 people in total for that day. I am completely baffled at why this script would hang under those specific circumstances, especially considering that this section of code has nothing to do with the appointment tables - it only uses the nurses table. Here is the section of code. If I comment out the stuff during the query (in the while loop) it works fine but with no nurse drop-down menu. If I do *ANYTHING* inside the while loop the code hangs. The query works fine under PHPMyAdmin.

if ($in{clinicdate} <= $today) { my $query="SELECT nurseid, fname, lname FROM nurses ORDER BY fname + ASC;"; my $dbh; my $sth; $dbh = DBI->connect("DBI:mysql:$dbname", $dbuser, $dbpass,{PrintEr +ror => 1, RaiseError => 1}); $sth=$dbh->prepare($query); $sth->execute(); print "$formstart\n\t\t<INPUT TYPE=HIDDEN NAME=\"f\" VALUE=\"Chang +eNurse\">\n\t\t\t<INPUT TYPE=HIDDEN NAME=\"clinicdate\" VALUE=\"$in{c +linicdate}\">\n\t\t\t<INPUT TYPE=HIDDEN NAME=\"clientid\" VALUE=\"$cl +ientid\">\n\t\t<SELECT NAME=\"nurseused\" onchange=\"this.form.submit +()\">\n\t\t\t<OPTION VALUE=\"\">Nurse</OPTION>"; while (@row=$sth->fetchrow()) { print "\n\t\t\t<OPTION VALUE=\"$row[0]\""; if ($nurseused{$clientid} eq $row[0]) { print " SELECTED"; } print ">$row[1] $row[2]</OPTION>"; } $sth->finish; $dbh->disconnect; print "\n\t\t\t<OPTION VALUE=\"0\" style=\"background-color:red\"> +NO SHOW!</OPTION>\n\t\t</SELECT>\n</FORM>"; } else { if ($confirmed{$clientid}==1) { print " X "; } }

In reply to perl hangs with a simple mySQL query by chuck

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.