CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
formatting tables

 



Zeke_D
Deleted

Nov 11, 2000, 1:10 PM

Post #1 of 8 (1400 views)
formatting tables Can't Post

I would like to soft this output into a nice table 6 columns wide. I just can't quite seem to get it - any ideas?
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


foreach $key (keys %include) {
if ($include{$key} eq 'yes') {
print "$key";
}
}
</pre><HR></BLOCKQUOTE>


sleuth
Enthusiast / Moderator

Nov 11, 2000, 1:30 PM

Post #2 of 8 (1400 views)
Re: formatting tables [In reply to] Can't Post

 
How do you mean, do you want $key to print in each column in the table?

Sleuth


Zeke_D
Deleted

Nov 11, 2000, 3:22 PM

Post #3 of 8 (1400 views)
Re: formatting tables [In reply to] Can't Post

sure do, before this snippet of code I am doing some bolean searching, and $key will be a link.


sleuth
Enthusiast / Moderator

Nov 12, 2000, 12:05 AM

Post #4 of 8 (1400 views)
Re: formatting tables [In reply to] Can't Post

 
I went and tried & tried & tried, but I could only accomplish two rows. LOL! Perl.com has some code for this, In there book actualy, if you have Perl Cookbook, look up columns in the back. That code is pretty confusing though, and the only time I've ever gotten anything out of perl.com's code give aways is the fisher yates shuffle.

I could give you the code for the rows if you want it, but I didn't post it this time because I didn't know if you had your heart set on 6.

A lot of people want to know how to do this yet I have only seen it used once, & that was in the Links1.0 program from gossamer-threads.com, It's said that you can modify it to print 20 columns if you want. It's too deep in there code to dig up quickly though.

But two column code still up for grabs!

Sleuth


Zeke_D
Deleted

Nov 12, 2000, 6:24 AM

Post #5 of 8 (1400 views)
Re: formatting tables [In reply to] Can't Post

Sure sleuth, 2 columns is better than 1 anyway :)


sleuth
Enthusiast / Moderator

Nov 12, 2000, 11:12 AM

Post #6 of 8 (1400 views)
Re: formatting tables [In reply to] Can't Post

 
Ok, this code is really cool.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


print qq~
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="532" height="1">
~;
open(data, "<test.db");
while(<data> ){
($number)=split(/\|/, $_);
$c++;
if ($c % 2){
print qq~
<tr>
<td height="1" width="266">
<p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">$number</font></b></td>
~;
}
if ($c % 2){}else{
print qq~
<td height="1" width="266">
<p align="center"><b><font size="2" face="Verdana" color="#FFFFFF"><i>$number</i></font></b></td>
~;
}
}
close(data);
print qq~
</tr> </table>
</center>
</div>
</body>
</html>
~;
</pre><HR></BLOCKQUOTE>

What it does is print the line of info in the <td tag but on every odd count, it prints a <tr>, that way it's able to print in the tables columns.

It's a round about way, but I guess that's why perl is known for having more than one way of doing things. :)

If you manage to swing this code into more columns, please let me know. No matter when.

Sleuth


Zeke_D
Deleted

Nov 12, 2000, 12:44 PM

Post #7 of 8 (1400 views)
Re: formatting tables [In reply to] Can't Post

Would this work?
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


print "<table border='0' cellpadding='0' cellspacing='0' WIDTH='100%'>";
foreach $key (keys %include) {
if ($include{$key} eq 'yes') {
$c++;
print "<td align='center'><FONT SIZE='-1'>$key</td>";
unless ($c % 6) {
print "<TR>";
}
}
}
print "</tr></table>";
</pre><HR></BLOCKQUOTE>

It works in the script I am working on - for example: http://www.yavapaiopen.com/netrep/index.cgi?year=2000&reply=search

Search for the word "netrep" and you will see what I mean.

[This message has been edited by Zeke_D (edited 11-12-2000).]


sleuth
Enthusiast / Moderator

Nov 12, 2000, 5:30 PM

Post #8 of 8 (1400 views)
Re: formatting tables [In reply to] Can't Post

 
GREAT!!!, You solved it! Yeppers that works great, Thanks for letting me know how you did it. I would have never thought of that, See, isn't % cool? he he, Great news Mate,

Sleuth

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives