473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Multiple records in rows

23
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
Expand|Select|Wrap|Line Numbers
  1. 01|Aaaa|
  2. 02|Bbbb|
  3. 03|Cccc|
  4. 04|Dddd|
  5. 05|Eeee|
  6. 06|Ffff|
  7. 07|Gggg|
  8. 08|Hhhh|
  9. 09|Iiii|
  10. 10|Jjjj|
  11. 11|Kkkk|
  12. 12|Llll|
  13.  
Perl script
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  4. print "Content-type: text/html\n\n";
  5. my $file="file.txt";
  6. my $num="3";
  7. my $rw="2"; ## this will be for number of rows shown
  8. my $pt="1";
  9.  
  10. # Don't like the foreach, but couldn't get while loop to do this.
  11. open(INF,"$file") or die("Can't open $file: $!"); my @md = <INF>; close(INF);
  12. print qq ~<table border="1"><tr>~;
  13.  
  14.  foreach my $line (@md) {chomp($line);
  15.  my @fd=split /\|/, "$line";
  16.  if ($pt == $num) {
  17.  print "<td>$fd[0]</td><td>$fd[1]</td></TR><TR>\n"; $pt=1;
  18.  }
  19.  else
  20.  {
  21.  if ($fd[0] ne "") {print "<td>$fd[0]</td><td>$fd[1]</td>\n"; $pt++;
  22.  }
  23.  }
  24.  }
  25.  
  26. print qq ~</tr></table>~;
  27. exit(0);
  28.  
I also don't want to use a module for this (can't understand most of them anyways).

Please can someone help.

Thanks beforehand
Nov 1 '14 #1

✓ answered by RonB

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 1737
Roamer
23
Anybody out there got an answer?
Nov 7 '14 #2
RonB
589 Expert Mod 512MB
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  4.  
  5. my $file = "file.txt";
  6. my $row  = 2;          ## this will be for number of rows shown
  7.  
  8. open my $fh, '<', $file or die "Can't open $file: $!";
  9.  
  10. print "Content-type: text/html\n\n";
  11. warningToBrowser(1);
  12.  
  13. print qq ~<table border="1">\n~;
  14.  
  15. while (my $line = <$fh>) {
  16.     chomp $line;
  17.     my @fd = split /\|/, $line;
  18.     print "  <tr><td>$fd[0]</td><td>$fd[1]</td></tr>\n";
  19.     last if $. == $row;
  20. }
  21. close $fh;
  22.  
  23. print qq ~</table>\n~;
  24. exit(0);
Nov 7 '14 #3
Roamer
23
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.....
Nov 7 '14 #4
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.
Nov 7 '14 #5
Roamer
23
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).
Nov 7 '14 #6
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.
Nov 7 '14 #7
Roamer
23
Got it sorted - thanks
Nov 13 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
0
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...
12
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...
4
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...
7
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...
0
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...
4
4Him
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:...
1
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??
6
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.