Multiple records in rows
Hi I have a partial solution working to show so many records in a row.
How to make it work so only, say, 2 rows show - I don't know how to do.
file.txt -
01|Aaaa|
-
02|Bbbb|
-
03|Cccc|
-
04|Dddd|
-
05|Eeee|
-
06|Ffff|
-
07|Gggg|
-
08|Hhhh|
-
09|Iiii|
-
10|Jjjj|
-
11|Kkkk|
-
12|Llll|
-
Perl script -
use strict;
-
use warnings;
-
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
-
print "Content-type: text/html\n\n";
-
my $file="file.txt";
-
my $num="3";
-
my $rw="2"; ## this will be for number of rows shown
-
my $pt="1";
-
-
# Don't like the foreach, but couldn't get while loop to do this.
-
open(INF,"$file") or die("Can't open $file: $!"); my @md = <INF>; close(INF);
-
print qq ~<table border="1"><tr>~;
-
-
foreach my $line (@md) {chomp($line);
-
my @fd=split /\|/, "$line";
-
if ($pt == $num) {
-
print "<td>$fd[0]</td><td>$fd[1]</td></TR><TR>\n"; $pt=1;
-
}
-
else
-
{
-
if ($fd[0] ne "") {print "<td>$fd[0]</td><td>$fd[1]</td>\n"; $pt++;
-
}
-
}
-
}
-
-
print qq ~</tr></table>~;
-
exit(0);
-
I also don't want to use a module for this (can't understand most of them anyways).
Please can someone help.
Thanks beforehand
You need pass parameters to the script that specify the number of rows to show and maybe even the starting point. For example, if you have 20 rows in the file and you want to show rows 5 starting with row 4, then you'd pass those numbers to the script via the query string (url).
The script would use a while loop to read the file and skip over the first few lines and process the next 5 lines and exit the loop after the 5th line it processed.
No need to load the file into an array.
7 1738
Anybody out there got an answer?
RonB 589
Expert Mod 512MB - use strict;
-
use warnings;
-
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
-
-
my $file = "file.txt";
-
my $row = 2; ## this will be for number of rows shown
-
-
open my $fh, '<', $file or die "Can't open $file: $!";
-
-
print "Content-type: text/html\n\n";
-
warningToBrowser(1);
-
-
print qq ~<table border="1">\n~;
-
-
while (my $line = <$fh>) {
-
chomp $line;
-
my @fd = split /\|/, $line;
-
print " <tr><td>$fd[0]</td><td>$fd[1]</td></tr>\n";
-
last if $. == $row;
-
}
-
close $fh;
-
-
print qq ~</table>\n~;
-
exit(0);
Hi Ron, thanks for that, but it's kind of going backwards for me. I started with something like a month ago and got to the point where I posted the thread.
I'm more an artist so programming is really hard for me. Let's go visual.
It's based on the ID (once I have that working the rest can be done by myself). So here's the concept:
01 02 03 (first row - 3 different records)
04 05 06 (second row - another 3 different records)
OR (could be several in a row)
01 02 03 04 .....
05 06 07 08 .....
etc-etc.
I probably would have no more than 4 rows of records (it's a blog script I wrote and this is for the homepage).
Hope I'm not being too much trouble, this thing's doing my head in.....
RonB 589
Expert Mod 512MB
I'm not sure what you're wanting/asking. Please rephrase your question and give an example of the desired output.
Hi again Ron, I'll try to explain.
The initial script shows the entire file. 4 rows with 3 records each. If I want to only show 2 of those rows, then somehow those rows have to be broken up in such a way that I can define how many rows I want to show.
I'm not even sure it can be done, but if so then good. If not, then I'll just have to leave it at only one row and be done with it.
The database is tiny, just 4 fields per record, so even a foreach could handle a couple thousand records.
I was thinking, open the file, in a while loop extract say 6 records and put them into an array. Then work from the array, using a foreach, rather than the whole file. I have looked all over the place and even tried PerlDoc (what a confusing site) to no avail.
I've never tried anything like this before because, normally, each blog entry is on it's own line. Putting say 3 entries on a line was different. I have seen the multi-line thing done, but I think it was in some other programming language (not sure which).
RonB 589
Expert Mod 512MB
You need pass parameters to the script that specify the number of rows to show and maybe even the starting point. For example, if you have 20 rows in the file and you want to show rows 5 starting with row 4, then you'd pass those numbers to the script via the query string (url).
The script would use a while loop to read the file and skip over the first few lines and process the next 5 lines and exit the loop after the 5th line it processed.
No need to load the file into an array.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andrew Chanter |
last post by:
I have a table containing multiple records per key. eg:
1 | John Smith
1 | Mary Brown
1 | Julie Grey
2 | Danny Pink
2 | Jill White
I need to consolidate this into a single record for each...
|
by: Patrick.O.Ige |
last post by:
I have a datagrid with checkboxes..
When a user clicks one check box and clicks the delete button it deletes
that ROw.
There another situation when a user clicks multiple rows so i had to loop...
|
by: shank |
last post by:
I'm trying to use online samples for submitting multiple records from ASP
into a stored procedure. Failing! Through the below form, a user could be
submitting many records at a time. I'm not...
|
by: musicloverlch |
last post by:
I have a table with multiple records in it. I am being forced to
combine multiple records into one record in order to be uploaded to a
website, and I only get one record per client. How can I...
|
by: Pim75 |
last post by:
Hello,
I want to store multiple records at once in a SQL database with a
For..Next instruction like the sample code below:
For counter = 0 To 100
Dim dbInsert As New SqlCommand( _
"INSERT...
|
by: qudra |
last post by:
Searching multiple records
--------------------------------------------------------------------------------
Hi guys. I need ur help.
In VB.NET we usually use this code to search the database...
|
by: 4Him |
last post by:
First off, let me say this is a great site! I've just started working with Access and much of my success is from what I've read here!
Background: I have a form, driven off a single table.
Goal:...
|
by: priyajee |
last post by:
Hai all,
I have joined two tables.My Query result is having multiple records
(ie) 8 Rows and 2 Columns..How can i display that multiple records in richtextbox?
Can anyone tell me??
|
by: Al Moodie |
last post by:
Hi,
I have a MySQL database where I want to updated multiple records. The
table has two columns:
product_number
product_price
I have a list with first entry product_price, second entry...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |