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: Advanced:
Help with output of database records.

 



CuzDesign
Deleted

Jan 15, 2001, 12:59 PM

Post #1 of 4 (1140 views)
Help with output of database records. Can't Post

Hello,
I am working on a program that gets information from records in a flatfile database. The problem I am having is with one of the fields in the database.

What I need to do is grab the information for the record than print it in the layout I choose, below is how the database is setup

(I Cannot Change the Way it is setup)


Code
C0270:20700.00:01:CHEVROLET:CP::MALIBU:BRIGHT WHITE/MD NEUTRAL CLOTH B:::1G1NE52J916107596:WHEELS:15 ALUMINUM:ALARM:1 
:::::::UCKET::::::
:::::::::::SPOILER:REAR DECK:DETAIL:
:::::::::::AM/FM STEREO CASS CD CLOCK::
:::::::::::CALIFORNIA EMISSION CERT.::
C10002:16610.00:01:CHEVROLET:CP::CAVALIER:ULTRA SILV.MET/GRAPHITE CLOTH I:::1G1JC124517124462:REMOTE KEYLESS ENTRY:ALARM:1
:::::::NT.TRIM::::::
:::::::::::MOLDING B/S DELUXE:DETAIL:
:::::::::::WIPER SYSTEM WINDSHIELD::
:::::::::::DEFOGGER RR WINDOW ELECTRIC::
:::::::::::CRUISE CONTROL ELECTRIC::
:::::::::::SPOILER:REAR DECK::
:::::::::::PREMIUM AMPLIFIED AUDIO 6 SPK::
:::::::::::ETR AM/FM STEREO W/CD::
:::::::::::SPORT PACKAGE::
:::::::::::CALIFORNIA EMISSION CERT.::
:::::::::::SUNROOF ELECTRIC::
:::::::::::STEERING COLUMN TILT TYPE::
:::::::::::WHEEL 115X6 STEEL::
:::::::::::TIRE ALL P195/65R15/N BL R/PE::

The filed I am having a problem with is [11] what I need to do is get all the info in that filed
untill the Next stock number comes up this way I am only printing one record instead of multiple.

Here is what I have so far:


Code
#!/usr/bin/perl 

print "Content-type: text/html\n\n";

use CGI qw(param);

$stock = param('stock');

open(INFILE,"<newinventory.txt") || die;
@trash = <INFILE>;
close(INFILE);

$record = 0;

foreach(@trash) {

if (($_ =~ /^:::::::/)&&($record == 1)) {
$_ =~ s/\n//g;
$_ =~ s/^::::::://;
$_ =~ s/(:*)$//;
@list = (@list,$_);
}else {
if($_ =~ /^$stock/) {
($first,$second,$third,$fourth,$fifth,$sixth,$seventh,$eigth,$nine,$ten,$eleven,$twelve,$thirten) = split(/:/,$_); # it should be ($first,$second,$third... bla bla bla). This is just an example
$id = $first;
$record = 1;
}else {
$record = 0;
}
}
}

print '<tr><td><font face="Verdana, Arial" color="#000000" size="-1"><b>'.$id.'</b></font>';
print '<font face="Verdana, Arial" color="#000000" size="-2"><li>'.$twelve.'</li></font>';
print '<font face="Verdana, Arial" color="#000000" size="-2"><li>'.$thirten.'</li></font>';
foreach $list(@list) {
print '<font face="Verdana, Arial" color="#000000" size="-2"><li>'.$list.'</li></font>';
}

This seems to work fine except when it prints It prints like so.


Code
C10033 
POWER SEAT
6-WAY DRIVER SIDE
::::CARGO NET LUGGAGE AREA
::::SEAT FRT BUCKET DELUXE
::::REMOTE KEYLESS ENTRY
::::SUNROOF ELECTRIC
::::TEMP CONTRL DRIVER AND PASS
::::DECAL ROADSIDE SERVICE INFO.
::::BRAKES:4-WHEEL DISC W/ABS
::::CRUISE CONTROL ELECTRIC
::::TIRES: P225/60R16N B/W TOURING
::::STEERING WHEEL CONTROLS
::::AM/FM STEREO CASS CD CLOCK
::::DRVR INFO CONVENIENCE CENTER
::::LABEL INFO BUMPER IMPACT 5 MPH
::::FRT. LICENSE PLATE DEPREESSIO
::::CALIFORNIA EMISSION CERT.
::::SPORT APPEARANCE PKG.

How can I get ride of the extra : before each option as well as control the layout.

Any help would be greatly appreciated.

Regards,
Ray



sleuth
Enthusiast

Jan 15, 2001, 3:14 PM

Post #2 of 4 (1138 views)
Re: Help with output of database records. [In reply to] Can't Post

 
Hey Ray, I'm glad to see you actually are able to read that database regardless of the format. Lately I've switched from one line records to multiple line records too so I actually though of how I could help you but it's been so long I though you'd have it by now. I guess I was right.

When you loop though your array to print the record. Add this line.

$list =~ s!^:+!!;

That should take care of it.

Sleuth



CuzDesign
Deleted

Jan 15, 2001, 6:37 PM

Post #3 of 4 (1134 views)
Re: Help with output of database records. [In reply to] Can't Post

Sleuth,
Thank you for your reply. I used the following to take
out the extra commas, seems to work great:

$list =~ tr/(,)//d;

On the other hand maybe someone can help me with the
next question I have. I want to control the way the options
are laid out on the page.

This is how they print to the browser now.
Example:
REMOTE KEYLESS ENTRY
ALARM
NT.TRIM
MOLDING B/S DELUXEDETAIL
WIPER SYSTEM WINDSHIELD
WHEEL 14 X 6 STEEL
TIRE ALL P195/70R14 BW
ETR AM/FM STEREO W/CD
CALIFORNIA EMISSION CERT.
DEFOGGER RR WINDOW ELECTRIC
SEAT FRT BUCKET DELUXE
2.2 LITER SFI L4 ENGINE
TRACTION ASSIST
4 SPEED AUTO TRANS

But I want to be able to print them out like so:

Example:

Code
REMOTE KEYLESS ENTRY                ALARM  
NT.TRIM MOLDING B/S DELUXEDETAIL
WIPER SYSTEM WINDSHIELD WHEEL 14 X 6 STEEL
TIRE ALL P195/70R14 BW ETR AM/FM STEREO W/CD
CALIFORNIA EMISSION CERT. DEFOGGER RR WINDOW ELECTRIC
SEAT FRT BUCKET DELUXE 2.2 LITER SFI L4 ENGINE
TRACTION ASSIST 4 SPEED AUTO TRANS

Any help here would be greatly appreciated.

Thanks in advance.
Ray



sleuth
Enthusiast

Jan 16, 2001, 2:42 AM

Post #4 of 4 (1132 views)
Re: Help with output of database records. [In reply to] Can't Post

 To do that, you have to be printing the results in a table. So print the open table first, then loop through the results, and print the close table.

In the loop,

print '<tr><td><font face="Verdana, Arial" color="#000000" size="-1"><b>'.$id.'</b></font>';
print '<font face="Verdana, Arial" color="#000000" size="-2"><li>'.$twelve.'</li></font>';
print '<font face="Verdana, Arial" color="#000000" size="-2"><li>'.$thirten.'</li></font>';
print qq~ <table border="0" cellpadding="0" cellspacing="0" width="100%" height="11">
<tr>~;
foreach $list(@list) {
print qq~
<td width="468" height="11"><font face="Verdana, Arial" color="#000000" size="-2">$list</font></td>
~;
$c++;
if ($c % 2){}else{
print "</tr><tr>";
}
}
print "<table>";

If I remember correctly that should do it. Just make it look the way you want. let me know.

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