List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:July 23 2000 8:57pm
Subject:Please help with simple perl/mysql
View as plain text  
I'm building a scheduling package for school and have a page that I want
to display
a table of all classes for that day with classroom numbers running
across the top and time down the left side.  It all works except that I
have five items in the database that it finds for Wed. and 3 of them are
at the same time 8:00 and it repeats the same row three times and then
moves on to the other info.

Thought I could include my code and if anyone could help shed light on
this problem - I'm not a code person by trade and arrays are magic to
me.  I guess I want to find out how I can stop the reps of rows if  the
time in is the same, so it won't query the database again if its already
done 8:00 even if there are 5 items found and 3 of them have the same
timein - so there must be something is mysql to do a query and grab the
number of results but have each result be unique?  This might solve my

The code is very basic - I just need a way to stop having it query the
database if the time in is the same so it will stop repeating rows with
the number of classes found with the same starting time.

I'm sending this to this list because perhaps there is something in
mysql that will stop this and also I have had nothing but the best help
on this list.

Thanks in advance,

------------------------------  code starts here----------------

use diagnostics;
use CGI;
use DBI;

#Setup main program
my $query= new CGI;

#Print out a contect type for http/1.0 compatibility
print $query->header("text/html");

#Grab the values from the form

my $D=$query->param("dayofweek");
#----- open database on Linux------------
my $dbh = DBI->connect("DBI:mysql:database:host","username","password");

#-----Create the command---------------
#Begin HTML output
print $query->start_html (-title =>'Database Query

#The \n's in the following code only affect the output of the
#info that comes back on the next screen.
if ($D eq "M") {
if ($D eq "T") {
if ($D eq "W") {
if ($D eq "R") {
if ($D eq "F") {
if ($D eq "S") {
if ($D eq "U") {

print "<font color=\"red\">";
#print data to screen for user to see
print "<h2><center>Scheduled Courses for $theday";
print "</h2></center></font></P>";
print "<center>";
print "<table border=\"1\"><tr><td>(Time/Room)</td>";
#--------------- Grab room info for top of table-------------
my $sth20 = $dbh->prepare("select room from room Order by room") or
bail_out("Cannot Connect");
my @arr=();
while (@arr = $sth20->fetchrow)
print "<td align=center>$theroom</td>";
print "</tr><tr>";
#--------------------------------------select beginning time for all
classes on day
my $sth9 = $dbh->prepare("select timein from courses where
done=\"Yes\" AND schdays LIKE \"\%$D\%\" order by timein") or
bail_out("Cannot Connect");
while (@record = $sth9->fetchrow)
if ($change ne $tm) {
print "</tr><tr>";
if ($change eq $tm) {
print "";
print "<td>$tm</td>";  #-----this prints out the starting time for each
#----------------- get room number ----------------
my $sth19 = $dbh->prepare("select room from room Order by room") or
bail_out("Cannot Connect");
while (@thatroom = $sth19->fetchrow)

#print "<td>@thatroom";
print "<td>";
#---------------------- get main ------------
my $sth1 = $dbh->prepare("select
from courses where done=\"Yes\" AND schdays LIKE \"\%$D\%\" AND
room=\"$theroom\" AND timein=\"$tm\" order by timein") or
bail_out("Cannot Connect");
my @arr=();
while (@arr = $sth1->fetchrow)
#--------------------------------- Print it out----
print "$csec, $ctitle <BR>";
print "$cschdays, $ctimein-$ctimeout<BR>$croom</td>";
print "</td></tr></table>";
print "<A Href=\"\">Back to Day Selection Menu</a>";
print $query->end_html;

------------------------------ End of Code-----------------------

Please help with simple perl/mysqlDouglas Brantz23 Jul
  • Re: Please help with simple perl/mysqlDouglas Brantz24 Jul