|
Joined: Sep 2000
Posts: 3
Junior Member
|
Junior Member
Joined: Sep 2000
Posts: 3 |
im having a little trouble with my script and one of the reasons is becuase its rather hard to explain the problem but here goes:
i have (well will have once i figure out how to do this) a dat file in the format; submissionnumber|categorynumber|datetime so it will have entries as such; 5|1|13/12/00 4|2|13/12/00 3|1|12/12/00 2|5|12/12/00 1|2|12/12/00
of course the date will be longer with the time and things but thats just an example
what i need is a little (or big depending on the complexity) code snipped for finding the highest submissionnumber for each categorynumber. hop here for the in progress script, as you can see (if you go there) i have got the time working for when you post a link im just haveing real trouble trying to getting the highest numbered link for each category
any help would be greatly appreciated
------------------ Please clean my floor
|
|
|
|
Joined: May 2000
Posts: 243
Member
|
Member
Joined: May 2000
Posts: 243 |
Im sure there are a few other people that I know that will have different opions. But you could use code like this to find how many rows are in your file. sub TotalRows { open (FILE, "filename.data"); @rows = ; close (FILE);
$Total = @rows; return($Total); }
$totalrows = &TotalRows;
So that gives you the amount of rows in your file. I think this will accomplish what you want to do
------------------ My Freeware Board
|
|
|
|
Joined: Sep 2000
Posts: 3
Junior Member
|
Junior Member
Joined: Sep 2000
Posts: 3 |
uh ahr, im a little confused about how knowing the amount of rows would help, ill try explaning in a little more detail:
if i had; 19|1|9/5/00 18|2|9/5/00 17|5|9/5/00 16|4|9/5/00 15|4|9/5/00 14|1|8/5/00 13|3|7/5/00 12|2|5/5/00 11|6|5/5/00 10|5|5/5/00 9|5|5/5/00 8|4|5/5/00 7|6|4/5/00 6|1|3/5/00 5|4|2/5/00 4|2|2/5/00 3|1|2/5/00 2|1|2/5/00 1|1|1/5/00
i would want my script to dismiss all of the lines except 19 (as that is the most recent post in column 1), 18 (most recent in 2), 13 (most recent in 3) 16 (most recent in 4), 17 (most recent in 5), 11 (most recent in 6)
i would then define those lines as something like: ($posted, $category, $date) = split(/|/,$line); (well line 19 as $1date, 18 $2date, 13 $3date etc..) therefore i would be looking for some type of script that would let me search from the top for the first 1 in the second column (in this case it is line 19) and use that line so i can then use that line to difine the 3rd column as $1date to use it as "last posted in" for column 1. ----------------------------
i could gain the same effect is i knew how to overwrite a file with a new one (or delete a file then replace it with one of the same name) however i presume that would use more sever processorage (i doubt it will be alot but i am using a UBB on netfirms so id rather use a very little as possible)
------------------ Please clean my floor
|
|
|
|
Joined: Aug 2000
Posts: 3,590
Moderator
|
Moderator
Joined: Aug 2000
Posts: 3,590 |
So ya want to read the first 10 lines of a file?? This should do it. EG: Then you can use a foreach statement to get the data from @line... ------------------ Da Wannabe Cannuck Andy Tomaka YaBB Developement Team [email protected] http://www.yabb.org [This message has been edited by atom911 (edited September 13, 2000).]
|
|
|
|
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
|
P.I.T.A. / Programmer
Joined: Sep 2000
Posts: 755 |
Where in the world are you guys getting the information that he wants to count the number of lines in a file, or get the first X lines??
He wants to extract the record containing the highest number id (column [0]) for each category (column [1]).
I see six categorys. Meaning he wants the result set to have six entries. One for each category, and it's corresponding id#. What's so hard about understanding that?
I don't have time to work out the algorithm for it right now, so you guys give it your best.
--mark
------------------
"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
|
|
|
|
Joined: Aug 2000
Posts: 3,590
Moderator
|
Moderator
Joined: Aug 2000
Posts: 3,590 |
Damn, I feel stupid. I got some homework to do, but I may throw something together tomorrow... ------------------ Da Wannabe Cannuck Andy Tomaka YaBB Developement Team [email protected] http://www.yabb.org [This message has been edited by atom911 (edited September 13, 2000).]
|
|
|
|
Joined: Sep 2000
Posts: 3
Junior Member
|
Junior Member
Joined: Sep 2000
Posts: 3 |
thanks very much all, expecially mark who did what i struggled to do look forward to seeing what you come up with but in the mean time another little question; i have variables named $date1, $date2, $date3 etc... and i also have a variable called $cat_num and i want to combine the 2 (ie $date$cat_num) so that i have £date"and then the number of the category here" but i dont know how, its in a foreach so i cant just specify $date1, $date2 etc.
------------------ Please clean my floor
|
|
|
|
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
|
P.I.T.A. / Programmer
Joined: Sep 2000
Posts: 755 |
Quick way: Can definatly be done more elegantly (using map) but im too tired to bother trying, --mark ------------------
"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 5,833
Joined: January 2000
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|