Professional Web Applications Themes

newbie Q: Using CSV instead of MySql - PHP Development

I have a bit of a problem, I am currently employed (as work study at a university) to maintain a rather large (5k files) site for the college I am attending. We are finally able to use PHP instead of just straight HTML but have no access to any database. My problem is this, I have over 50 employees in one department and I must list their name, extention, e-mail address, picture and homepage URL (old eg: at [url]http://arapaho.nsuok.edu/~cbi/faculty[/url]). I have all the faculty data in a csv file but I cannot find anything on how to use PHP a ...

  1. #1

    Default newbie Q: Using CSV instead of MySql

    I have a bit of a problem, I am currently employed (as work study at a
    university) to maintain a rather large (5k files) site for the college I am
    attending. We are finally able to use PHP instead of just straight HTML but
    have no access to any database.

    My problem is this, I have over 50 employees in one department and I
    must list their name, extention, e-mail address, picture and homepage URL
    (old eg: at [url]http://arapaho.nsuok.edu/~cbi/faculty[/url]). I have all the faculty
    data in a csv file but I cannot find anything on how to use PHP a csv
    together. I want to be able to list all faculty by either department or name
    and have the code generated.

    if anyone can either help me or point me in the right direction I would
    appreciate it.
    --

    N8
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Build a man a fire and he'll be warm for a few hours
    Set a man on fire and he'll be warm the rest of his life
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    Citizen X Guest

  2. #2

    Default Re: newbie Q: Using CSV instead of MySql

    "Citizen X" <landryn8NO_SPAMhotmail.com> a écrit dans le message de
    news:bl21e30op2enews2.newsguy.com...
    > I have a bit of a problem, I am currently employed (as work study at a
    > university) to maintain a rather large (5k files) site for the college I
    am
    > attending. We are finally able to use PHP instead of just straight HTML
    but
    > have no access to any database.
    >
    > My problem is this, I have over 50 employees in one department and I
    > must list their name, extention, e-mail address, picture and homepage URL
    > (old eg: at [url]http://arapaho.nsuok.edu/~cbi/faculty[/url]). I have all the faculty
    > data in a csv file but I cannot find anything on how to use PHP a csv
    > together. I want to be able to list all faculty by either department or
    name
    > and have the code generated.
    >
    > if anyone can either help me or point me in the right direction I would
    > appreciate it.
    > --
    >
    > N8
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    > Build a man a fire and he'll be warm for a few hours
    > Set a man on fire and he'll be warm the rest of his life
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    >
    >
    Try something like this :
    <?
    $Path = "path/to/your/csv";
    $Data = array();
    $fp = fopen($Path,"r");
    $Content = str_replace("\r","",fread($fp,filesize($Path)));
    fclose($fp);
    $Lines = explode("\n",$Content);
    unset($Content);
    list($Key,$Val) = each($Lines);
    $Keys = explode(";",$Val);
    while (list($Key,$Val) = each($Lines)) {
    $Col = explode(";",$Val);
    foreach ($Col as $ColKey=>$ColVal) {
    $Data[$Key][$Keys[$ColKey]] = $ColVal;
    }
    }
    ?>

    Now, you've got a $Data array which contains all the data of the csv file.

    To understand what it contains, add this :
    <? print_r($Data); ?>




    Benjamin Morel Guest

  3. #3

    Default Re: newbie Q: Using CSV instead of MySql

    On Fri, 26 Sep 2003 21:30:37 +0200, "Benjamin Morel" <virtuanerim.fr> wrote:
    >"Citizen X" <landryn8NO_SPAMhotmail.com> a écrit dans le message de
    >news:bl21e30op2enews2.newsguy.com...
    >> I have a bit of a problem, I am currently employed (as work study at a
    >> university) to maintain a rather large (5k files) site for the college I
    >am
    >> attending. We are finally able to use PHP instead of just straight HTML
    >but
    >> have no access to any database.
    >>
    >> My problem is this, I have over 50 employees in one department and I
    >> must list their name, extention, e-mail address, picture and homepage URL
    >> (old eg: at [url]http://arapaho.nsuok.edu/~cbi/faculty[/url]). I have all the faculty
    >> data in a csv file but I cannot find anything on how to use PHP a csv
    >> together. I want to be able to list all faculty by either department or
    >name
    >> and have the code generated.
    >>
    >> if anyone can either help me or point me in the right direction I would
    >> appreciate it.
    >
    >Try something like this :
    ><?
    >$Path = "path/to/your/csv";
    >$Data = array();
    >$fp = fopen($Path,"r");
    >$Content = str_replace("\r","",fread($fp,filesize($Path)));
    >fclose($fp);
    >$Lines = explode("\n",$Content);
    >unset($Content);
    >list($Key,$Val) = each($Lines);
    >$Keys = explode(";",$Val);
    >while (list($Key,$Val) = each($Lines)) {
    > $Col = explode(";",$Val);
    (From the looks of your code you're actually parsing semicolon-separated
    files?)
    > foreach ($Col as $ColKey=>$ColVal) {
    > $Data[$Key][$Keys[$ColKey]] = $ColVal;
    > }
    >}
    >?>
    >
    >Now, you've got a $Data array which contains all the data of the csv file.
    You can simplify that down a lot and avoid reinventing the wheel, using PHP's
    built in CSV support:

    [url]http://uk2.php.net/fgetcsv[/url]

    --
    Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  4. #4

    Default Re: newbie Q: Using CSV instead of MySql

    "Andy Hassall" <andyandyh.co.uk> a écrit dans le message de
    news:6559nvom85c4029cbifth720bcl4n0dnpo4ax.com...
    > On Fri, 26 Sep 2003 21:30:37 +0200, "Benjamin Morel" <virtuanerim.fr>
    wrote:
    >
    > >"Citizen X" <landryn8NO_SPAMhotmail.com> a écrit dans le message de
    > >news:bl21e30op2enews2.newsguy.com...
    > >> I have a bit of a problem, I am currently employed (as work study at a
    > >> university) to maintain a rather large (5k files) site for the college
    I
    > >am
    > >> attending. We are finally able to use PHP instead of just straight HTML
    > >but
    > >> have no access to any database.
    > >>
    > >> My problem is this, I have over 50 employees in one department and
    I
    > >> must list their name, extention, e-mail address, picture and homepage
    URL
    > >> (old eg: at [url]http://arapaho.nsuok.edu/~cbi/faculty[/url]). I have all the
    faculty
    > >> data in a csv file but I cannot find anything on how to use PHP a csv
    > >> together. I want to be able to list all faculty by either department or
    > >name
    > >> and have the code generated.
    > >>
    > >> if anyone can either help me or point me in the right direction I would
    > >> appreciate it.
    > >
    > >Try something like this :
    > ><?
    > >$Path = "path/to/your/csv";
    > >$Data = array();
    > >$fp = fopen($Path,"r");
    > >$Content = str_replace("\r","",fread($fp,filesize($Path)));
    > >fclose($fp);
    > >$Lines = explode("\n",$Content);
    > >unset($Content);
    > >list($Key,$Val) = each($Lines);
    > >$Keys = explode(";",$Val);
    > >while (list($Key,$Val) = each($Lines)) {
    > > $Col = explode(";",$Val);
    >
    > (From the looks of your code you're actually parsing semicolon-separated
    > files?)
    >
    > > foreach ($Col as $ColKey=>$ColVal) {
    > > $Data[$Key][$Keys[$ColKey]] = $ColVal;
    > > }
    > >}
    > >?>
    > >
    > >Now, you've got a $Data array which contains all the data of the csv
    file.
    >
    > You can simplify that down a lot and avoid reinventing the wheel, using
    PHP's
    > built in CSV support:
    >
    > [url]http://uk2.php.net/fgetcsv[/url]
    >
    :)
    I didn't know this :)


    Benjamin Morel Guest

  5. #5

    Default Re: newbie Q: Using CSV instead of MySql

    Or you could use XML ....

    Or sqLite...

    "Benjamin Morel" <virtuanerim.fr> wrote in message
    news:bl24ui$30na$1biggoron.nerim.net...
    > "Andy Hassall" <andyandyh.co.uk> a écrit dans le message de
    > news:6559nvom85c4029cbifth720bcl4n0dnpo4ax.com...
    > > On Fri, 26 Sep 2003 21:30:37 +0200, "Benjamin Morel" <virtuanerim.fr>
    > wrote:
    > >
    > > >"Citizen X" <landryn8NO_SPAMhotmail.com> a écrit dans le message de
    > > >news:bl21e30op2enews2.newsguy.com...
    > > >> I have a bit of a problem, I am currently employed (as work study at
    a
    > > >> university) to maintain a rather large (5k files) site for the
    college
    > I
    > > >am
    > > >> attending. We are finally able to use PHP instead of just straight
    HTML
    > > >but
    > > >> have no access to any database.
    > > >>
    > > >> My problem is this, I have over 50 employees in one department
    and
    > I
    > > >> must list their name, extention, e-mail address, picture and homepage
    > URL
    > > >> (old eg: at [url]http://arapaho.nsuok.edu/~cbi/faculty[/url]). I have all the
    > faculty
    > > >> data in a csv file but I cannot find anything on how to use PHP a csv
    > > >> together. I want to be able to list all faculty by either department
    or
    > > >name
    > > >> and have the code generated.
    > > >>
    > > >> if anyone can either help me or point me in the right direction I
    would
    > > >> appreciate it.
    > > >
    > > >Try something like this :
    > > ><?
    > > >$Path = "path/to/your/csv";
    > > >$Data = array();
    > > >$fp = fopen($Path,"r");
    > > >$Content = str_replace("\r","",fread($fp,filesize($Path)));
    > > >fclose($fp);
    > > >$Lines = explode("\n",$Content);
    > > >unset($Content);
    > > >list($Key,$Val) = each($Lines);
    > > >$Keys = explode(";",$Val);
    > > >while (list($Key,$Val) = each($Lines)) {
    > > > $Col = explode(";",$Val);
    > >
    > > (From the looks of your code you're actually parsing
    semicolon-separated
    > > files?)
    > >
    > > > foreach ($Col as $ColKey=>$ColVal) {
    > > > $Data[$Key][$Keys[$ColKey]] = $ColVal;
    > > > }
    > > >}
    > > >?>
    > > >
    > > >Now, you've got a $Data array which contains all the data of the csv
    > file.
    > >
    > > You can simplify that down a lot and avoid reinventing the wheel, using
    > PHP's
    > > built in CSV support:
    > >
    > > [url]http://uk2.php.net/fgetcsv[/url]
    > >
    >
    > :)
    > I didn't know this :)
    >
    >

    point Guest

  6. #6

    Default Re: newbie Q: Using CSV instead of MySql

    "Citizen X" <landryn8NO_SPAMhotmail.com> wrote in message
    news:bl21e30op2enews2.newsguy.com...
    > I have a bit of a problem, I am currently employed (as work study at a
    > university) to maintain a rather large (5k files) site for the college I
    am
    > attending. We are finally able to use PHP instead of just straight HTML
    but
    > have no access to any database.
    >
    > My problem is this, I have over 50 employees in one department and I
    > must list their name, extention, e-mail address, picture and homepage URL
    > (old eg: at [url]http://arapaho.nsuok.edu/~cbi/faculty[/url]). I have all the faculty
    > data in a csv file but I cannot find anything on how to use PHP a csv
    > together. I want to be able to list all faculty by either department or
    name
    > and have the code generated.
    >
    > if anyone can either help me or point me in the right direction I would
    > appreciate it.
    > --
    >
    > N8
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    > Build a man a fire and he'll be warm for a few hours
    > Set a man on fire and he'll be warm the rest of his life
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Hi Citizen X,

    May I suggest using a class I have constructed that provides a 'poorman's
    database using CSV files.

    [url]http://ronbarnett.users.phpclasses.org/[/url]

    Follow this link to PHP classes and look foe Class.DB in the Files and
    Directories section, or browse by author on my name.

    I use the class with great success with files much larger than 5k.

    The class has a case and space insensitive 'find' that permits one to many
    set retrievals, delete, append (insert) and update functions. Although the
    API is not written to be 'SQL like' you could always add a wrapper if you
    felt the need for better separation of database function from application
    code.

    Happy coding

    Ron.




    Ron Guest

  7. #7

    Default Re: newbie Q: Using CSV instead of MySql

    On Fri, 26 Sep 2003 21:46:55 +0200, Benjamin Morel wrote:
    >> You can simplify that down a lot and avoid reinventing the wheel, using
    >PHP's
    >> built in CSV support:
    >>
    >> [url]http://uk2.php.net/fgetcsv[/url]
    >
    >I didn't know this :)
    a helpful first step research tool is the site search on [url]www.php.net[/url]
    -- for example [url]http://www.google.com/search?q=csv+site:www.php.net[/url]
    brings up all kinds of interesting links about csv support, among them
    the function andy mentioned.
    Gerhard Fiedler Guest

Similar Threads

  1. mysql error [newbie]
    By Frel in forum MySQL
    Replies: 4
    Last Post: August 27th, 08:29 AM
  2. newbie question with php and mysql
    By levels in forum Macromedia Dynamic HTML
    Replies: 4
    Last Post: August 25th, 12:18 PM
  3. Newbie tutorial for MySQL/OS X?
    By Tim McNamara in forum MySQL
    Replies: 2
    Last Post: January 30th, 01:37 AM
  4. Newbie:MySQL problem
    By Ivan Fiala in forum PHP Development
    Replies: 3
    Last Post: January 2nd, 07:29 AM
  5. NEWBIE PHP MySQL Windowa XP
    By HMW in forum PHP Development
    Replies: 0
    Last Post: September 21st, 01:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139