Subject: selecting data from file with php

From: Date: Sat, 09 Aug 2003 09:55:27 +0000
Subject: Subject: selecting data from file with php
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-21090@lists.php.net to get a copy of this message
I would do something like this, your mileage may vary. Lines starting with // are comments. $addresscities=array(); // Make an empty array $resultrows=file("address.txt"); // This creates an array of lines of the file, one element per line foreach ($resultrows as $line) {
        $row=explode("\t",$line);
// Chop up the row into 3 fields separated by the tab (\t) character // You must use double quotes for PHP to read \t as a tab character
        $addresscities[$row[2]]=        $addresscities[$row[2]]+1;
// Add a count of one to the value in $addresscities[cityname] // If an array element like that does not exist it will be created // and one added to its initial value (effctoiely, zero), making a count of 1. } // End looping though the result rows ksort($addresscities); // Sort the array keys (city names) alphabetically You now have an array containing entries like : $addresscities["dallas"] ........ 15 $addresscities["mexico"] ........ 1 or whatever. You can do pretty much what you want with that data. In SQL you would import the file once as a CSV or similar format, then do : SELECT city, COUNT(city) AS address GROUP BY city ORDER BY city to get a summary of people in each city. Much simpler, isn't it ? ;-) I would definitely go with SQL for address data, you can get complex breakdowns of data with almost no re-programming, and this sort of data is made for a database ! Cheers - Neil. I do not accept mail from hotmail yahoo or other free accounts. Please reply only on list. All mail from these accounts *will* be bounced and the account blacklisted. Thankyou. At 19:00 08/08/2003 +0000, you wrote:
Message-ID: <20030808190012.62405.qmail@web40514.mail.yahoo.com> Date: Fri, 8 Aug 2003 12:00:12 -0700 (PDT) From: Idur <bakpia_lumpia@yahoo.com> To: php-windows@lists.php.net MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-779152822-1060369212=:59102" Subject: selecting data from file with php hi there,.... i have file address.txt, it's content of address of customer, like this ;
name   age     city
jony      27   new york
george 25 dallas
mony     23   mexico
edward 30 new york
budy     22    dallas
dennise 21 new york hox to count the field of city, so the result is, like this
city         count
dallas         2
new york     3
mexico        1
so i know how many user from a specific city, for the information i am not using mysql. Is that to difficult to do it with out mysql...?? Did php have the function to do selecting data like mysql....??? thanx
======================================================== CaptionKit http://www.captionkit.com : Production tools for accessible subtitled internet media, transcripts and searchable video. Supports Real Player, Quicktime and Windows Media Player. VideoChat with friends online, get Freshly Toasted every day at http://www.fresh-toast.net : NetMeeting solutions for a connected world.

« previous php.windows (#21090) next »