Jump to content

CSV Parser


3s2ng

Recommended Posts

Hello Freaks,

I want to create a page like http://www.royalgojiteam.com/recognition_advancements.php but no database only CSV file.

How can I manage a page like that? The page is categories based on 1 field in the CSV in this case it the Title(ex. Royal Ambassadors, Ambassador V, etc.)

Sample Xls file:
[table]
[tr]
[td]Primary Last Name[/td]
[td]Primary First Name[/td]
[td]Secondary Last Name[/td]
[td]Secondary First Name[/td]
[td]Email[/td]
[td]Title[/td]
[td]State[/td]
[td]Password[/td]
[/tr]

[tr]
[td]McEachern[/td]
[td]Keith[/td]
[td]Secondary Last Name[/td]
[td]Secondary First Name[/td]
[td]keithmceachern@aol.com[/td]
[td]Royal Ambassador IV[/td]
[td]CT[/td]
[td]pwd[/td]
[/tr]

[tr]
[td]Estong[/td]
[td]Capio[/td]
[td][/td]
[td][/td]
[td]test@aol.com[/td]
[td]Royal Ambassador[/td]
[td]AZ[/td]
[td]123[/td]
[/tr]
[/table]

Sample CSV
Primary Last Name,Primary First Name,Secondary Last Name,Secondary First Name,Email,Title,ST,Password
McEachern,Keith,,,keithmceachern@aol.com,Royal Ambassador IV,CT,km5555
Moreland,Keith,,,free4lifekm@ris.net,Royal Ambassador IV,CO,klmsmm

How can I parse the csv to be placed in that kind of layout?

Thanks in advance.

Link to comment
Share on other sites

Thanks for the Reply AndyB.

I want to display categorically.

Like if 1 listing has a title "Ambasador" I want to get that line and save it in an array. So it will display all listings with title "Ambassador" in the Ambassado category.

Link to comment
Share on other sites

as long as you're not using incredibly large CSV files, you'll be fine. you'll still have to parse through each record to sort since there is no engine within a flat file to sort by or filter. check out fgetcsv() as well:
[code]
<?php
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  $num = count($data);
  echo "<p> $num fields in line $row: <br /></p>\n";
  $row++;
  for ($c=0; $c < $num; $c++) {
      echo $data[$c] . "<br />\n";
  }
}
fclose($handle);
?>
[/code]

hope that helps
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.