Results 1 to 8 of 8

Thread: is this possible

  1. #1
    Download 09 FTW TiMeZeRo's Avatar
    Join Date
    Aug 2005
    Location
    Cambridge, UK
    Posts
    831
    Thanks
    0
    Thanked
    1 time in 1 post

    is this possible

    is it possible without using mysql

    to have 2 text files laid out like for example

    28/08/09
    band1
    29/08/09
    band2

    and a php file read from it and put them on a page as

    for example

    Wed 8th August - band 1 <-- i know date aint right just example

    if that is possible how much harder is it to get when the php file loads it take off any dates taht have passed and move them onto the bottom of text file 2 setup exactly the same way for achive purposes

    im not sure this is even possible but if u guys can give me a nudge in the right direction it would help

    because of lack of mysql database i figure this is guna be alot harder than if i had one
    EVE - Online ( TiMeZeRo225, Proper Emo, Facter )
    World of Warcraft:
    Eu:The Shattar ( TiMeZeRo )
    Eu:Shattered halls (Pakapunch, Sigari, Eitu)
    CS:S - TiMeZeRo

  2. #2
    Registered+
    Join Date
    Apr 2005
    Location
    Manchester
    Posts
    36
    Thanks
    0
    Thanked
    1 time in 1 post

    Re: is this possible

    It's possible, but if you're going to have any number of visitors beyond a handful, you'll probably run into problems.

    You need to parse the folder (http://codingforums.com/showthread.php?t=71882), opening each text file & read it in. You can (probably, I've never tried from the format you have) format the date with:
    PHP Code:
    date_format(date_create($yourdatestring), "D jS F"); 

  3. #3
    Download 09 FTW TiMeZeRo's Avatar
    Join Date
    Aug 2005
    Location
    Cambridge, UK
    Posts
    831
    Thanks
    0
    Thanked
    1 time in 1 post

    Re: is this possible

    this is what ive come up with so far but it seems to be trying to convert to date on both buffer and buffer2 how can i make it not try and convert for both lines of th text file

    <?php
    $fh = @fopen('data/1.txt', 'r');
    if ($fh) {
    while (!feof($fh)) { //loop for pointer to go to each line
    $buffer = fgets($fh);//reading date line
    $date1 = date_format(date_create($buffer), "D jS F"); // converting date to text
    $buffer2 = fgets($fh);//reading event line
    echo $date1," - ", $buffer2, "<br>"; //displaying line
    $buffer1.=$buffer; //storing whole text of file in $buffer1 for any future use
    }
    fclose($fh);
    }
    ?>

    basically buffer2 var is plain text of who is playing that day e.g. not a date at all hence it throwing up errors but im not sure how to get round this
    EVE - Online ( TiMeZeRo225, Proper Emo, Facter )
    World of Warcraft:
    Eu:The Shattar ( TiMeZeRo )
    Eu:Shattered halls (Pakapunch, Sigari, Eitu)
    CS:S - TiMeZeRo

  4. #4
    cmd
    cmd is offline
    Registered+
    Join Date
    Sep 2009
    Posts
    28
    Thanks
    0
    Thanked
    3 times in 3 posts

    Re: is this possible

    This seems to do everything you asked for, but I didn't test it very thoroughly:
    PHP Code:
    <?php

    $data1 
    'data/1.txt';
    $data2 'data/2.txt';

    $fh fopen($data1,'r');

    $writeData1 "";
    $writeData2 "";

    if (
    $fh) {
        while (!
    feof($fh)) {
            
    $currentDate fgets($fh);
            
    $currentBand fgets($fh);

            list(
    $day$month$year) = explode('/'$currentDate);
            
    $currentDateToPHPTime mktime(000$month$day$year);
            
            if (
    $currentDateToPHPTime >= mktime(000date('m'), date('d'), date('y'))) {
                
    $writeData1 .= $currentDate $currentBand;
                echo 
    date("D jS F"$currentDateToPHPTime) . ' - ' $currentBand '<br />';
            } else {
                
    $writeData2 .= $currentDate $currentBand;
            }
        }
    }
    fclose($fh);

    //echo '<br /><br />$data1: ' . $writeData1 . '<br />$data2: '. $writeData2; 

    file_put_contents($data1$writeData1);
    file_put_contents($data2$writeData2FILE_APPEND);

    ?>

  5. #5
    HEXUS webmaster Steve's Avatar
    Join Date
    Nov 2003
    Posts
    14,283
    Thanks
    293
    Thanked
    841 times in 476 posts

    Re: is this possible

    Are you limited because your host isn't providing mysql servers? Is SQLite support possible?
    PHP Code:
    $s = new signature();
    $s->sarcasm()->intellect()->font('Courier New')->display(); 

  6. #6
    cmd
    cmd is offline
    Registered+
    Join Date
    Sep 2009
    Posts
    28
    Thanks
    0
    Thanked
    3 times in 3 posts

    Re: is this possible

    SQLite would be much nicer.

    I just noticed that code I posted rewrites both text files every page load even if nothing has changed, which is inefficient.

  7. #7
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: is this possible

    indeed, if your writing your own data persistence layer for something so pedestrian your doing it wrong.
    throw new ArgumentException (String, String, Exception)

  8. #8
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: is this possible

    Can't agree anywhere near enough that you need a database of some description for this, but if that *absolutely* isn't an option, you'd be better off using a delimited file format, reading one line at a time, then splitting that line around the delimiter (I assume PHP has a split function). So your file would look like:

    28/08/09#Band 1
    29/08/09#Band 2
    01/09/09#Wayward Smile

    and your script would read a line, split it around '#'. This should return a 2 element array with the date in the first element and the band name in the second, which you can use in your page.

    You can do this using dbm and hashes in Perl (dbm is a pre-written module that handles retrieving and writing flat-file databases), but I'm afraid I've not played with php enough to know if it has something similar...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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