Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl: DBI problem

Status
Not open for further replies.

Blood22

Technical User
Jul 14, 2003
7
GB
In theory I know what I need but I cannot put it into Perl!
I am creating a schedule table that pulls dates and times from a MySQL table and if they exist highlights a html table.

I need something like this:

print "table...
print "table cell...
test a mysql select statement
print "table cell bgcolor =
red if true or white if false"

print another "table cell...
test a mysql select statement
print "table cell bgcolor =
red if true or white if false"

At present I can only figure out how to connect to the db and retrieve 1 SELECT statement! I don't know how to use multiple statements like I wish to use above. ANY help on this is really appreciated!

Si22.

 
Blood,

Work on generating the table without highlighting first. When you have that code up and running, it'll be easy change as you loop through the array

print &quot;<table width=\&quot;XX\&quot;>&quot;;
print &quot;<whole load of stuff>&quot;;
while ([..processing recordset..]) {
if ([..condition..]) {
$bgcolor=&quot;red&quot;;
} else {
$bgcolor=&quot;white&quot;;
}
print &quot;<td gbcolor=$bgcolor>$variable</td>&quot;;
$colcnt++;
if ($collcnt>$colmax) {
$collcnt=1;
print &quot;</tr><tr>&quot;;
}
}

HTH
--Paul
 
Hi,

If you do not store the SELECT statement output each row at a time (or use it as you retreive it, as I've done in the example) then the SELECT statement will only return the last match.

Heres a potential solution ...

print &quot;<table>&quot;;
print &quot;<tr><th>Date</th><th>Time</th></tr>&quot;;
$sth = $dbh->prepare (&quot;SELECT date,time FROM yourtable&quot;);
$sth->execute();
while (my @val = $sth->fetchrow_array())
{
print &quot;<tr><td>$val[0]</td><td>$val[1]</td></tr>&quot;;
}
$sth->finish();
print &quot;</table>&quot;;


... within the while loop you will be able to add conditions to change formatting etc...

Let me know how you get on...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top