php forum
php mysql forum
php mysql smarty
 
Topic Options
#101196 - 09/13/00 02:59 PM finding the highest number in a .dat file
Humpty Dumpty Offline
Junior Member

Registered: 09/13/00
Posts: 6
Loc: England
<FONT size="2">
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
</FONT s>

------------------
Please clean my floor
_________________________
Please clean my floor

Top
#101197 - 09/13/00 04:00 PM Re: finding the highest number in a .dat file
zanardi Offline
Member

Registered: 05/30/00
Posts: 635
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 = <FILE>;
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

Top
#101198 - 09/13/00 04:49 PM Re: finding the highest number in a .dat file
Humpty Dumpty Offline
Junior Member

Registered: 09/13/00
Posts: 6
Loc: England
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
_________________________
Please clean my floor

Top
#101199 - 09/13/00 07:07 PM Re: finding the highest number in a .dat file
The Team Offline
Moderator

Registered: 08/11/00
Posts: 182
Loc: yes
So ya want to read the first 10 lines of a file?? This should do it.

EG:

Quote:
quote:


Then you can use a foreach statement to get the data from @line...


------------------
Da Wannabe Cannuck

Andy Tomaka
YaBB Developement Team
AndyTomaka@yabb.org http://www.yabb.org

[This message has been edited by atom911 (edited September 13, 2000).]

Top
#101200 - 09/13/00 08:20 PM Re: finding the highest number in a .dat file
Mark Badolato Offline
P.I.T.A. / Programmer

Registered: 09/08/00
Posts: 836
Loc: Land O' Cactus
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

Top
#101201 - 09/13/00 08:23 PM Re: finding the highest number in a .dat file
The Team Offline
Moderator

Registered: 08/11/00
Posts: 182
Loc: yes
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
AndyTomaka@yabb.org http://www.yabb.org

[This message has been edited by atom911 (edited September 13, 2000).]

Top
#101202 - 09/13/00 10:00 PM Re: finding the highest number in a .dat file
Humpty Dumpty Offline
Junior Member

Registered: 09/13/00
Posts: 6
Loc: England
<FONT size="2">
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.
</FONT s>

------------------
Please clean my floor
_________________________
Please clean my floor

Top
#101203 - 09/13/00 11:27 PM Re: finding the highest number in a .dat file
Mark Badolato Offline
P.I.T.A. / Programmer

Registered: 09/08/00
Posts: 836
Loc: Land O' Cactus
Quick way:

Code:
code:


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

Top



Latest Posts
[7.2.1] - Naked shoutbox
by bellaonline
05/05/12 05:00 PM
[7.x] Stop Forum Spam Integration v0.4
by bellaonline
05/05/12 03:53 PM
Shout Box

(Views)Popular Topics
Known public proxy servers 1689885
Integrated Index Page (IIP) 5.3.1 555705
Finished-[6.5.2] Games Arcade Deluxe v1.9 501236
Integrated Index Page (IIP) 5.1.1 415112
TLD Bv2.1 Released - Threads Links Directory 396822
[6.0x] Who's Online 4.0.0 [Finished] 389412
Finished-[6.5.1] Integrated Index Page (IIP) 6.5 330423
Q & A 298663
Slash UBB 266936
[6.3.x] [beta] Hit Hack 2.0 227970
Forum Stats
13621 Members
59 Forums
37191 Topics
295716 Posts

Max Online: 686 @ 06/28/07 07:04 AM

 

 

 
fusionbb message board php hacks