www.webdeveloper.com
Results 1 to 7 of 7

Thread: Could someone point me in the right direction?

  1. #1
    Join Date
    Jan 2003
    Posts
    49

    Could someone point me in the right direction?

    I'm building a gaming site, and I need to get some database (not mySQL, please, I can't even get it installed, I'm no PHPist ) where I can have an admin and add a category from it (which would be playstation 2, xbox, etc) and then categories inside those (the games) and in the games, I can add all the cheats, hints & tips, reviews etc from the admin. I just need to be pointed in the right direction. Thanks...

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Generally, when one uses PHP, mySQL is the database that is used. What exactly are you looking for?

  3. #3
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    MySQL is probably the best database to use, though I believe PostgreSQL might be an option, though I haven't tried it myself.

    If you are using MySQL, phpMyAdmin is a very useful tool:
    http://www.phpmyadmin.net/

    Adam

  4. #4
    Join Date
    Jan 2003
    Posts
    49
    I tried phpMyAdmin before... I couldn't get it installed either rofl. I'll try again. Thanks anyways.

  5. #5
    Join Date
    Jan 2003
    Posts
    49
    Auctually, could someone just give me some PHP code that will write some text to a file and another PHP code to get the text in the file?

  6. #6
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    To get the text in a file (straight dump to browser):
    PHP Code:
    <?php include "filename.txt" ?>
    To read the file and parse newlines to <br>s (suitable for HTML):
    PHP Code:
    <?php
      $text_array 
    file("filename.txt");
      
    $text implode(""$text_array);
      print 
    nl2br($text);
    ?>
    To write to a file (example from www.php.net):
    PHP Code:
    <?php
    $filename 
    'test.txt';
    $somecontent "Add this to the file\n";

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

        
    // In our example we're opening $filename in append mode.
        // The file pointer is at the bottom of the file hence 
        // that's where $somecontent will go when we fwrite() it.
        
    if (!$handle fopen($filename'a')) {
             print 
    "Cannot open file ($filename)";
             exit;
        }

        
    // Write $somecontent to our opened file.
        
    if (!fwrite($handle$somecontent)) {
            print 
    "Cannot write to file ($filename)";
            exit;
        }
        
        print 
    "Success, wrote ($somecontent) to file ($filename)";
        
        
    fclose($handle);
                        
    } else {
        print 
    "The file $filename is not writable";
    }
    ?>
    Adam

  7. #7
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    To write to a file: (file must be CHMODed to 666)

    PHP Code:
    <?PHP

    $filename 
    "file.txt";
    $text "This is a demo.";

    $fp fopen ($filename"w");
    if (
    $fp) {
        
    fwrite ($fp$text);
        
    fclose ($fp);
        echo (
    "File written");
    }
    else {
        echo (
    "File was not written");
    }

    ?>
    To read from a file:

    PHP Code:
    <?PHP

    $filename 
    "file.txt";

    $fp fopen ($filename"r");
    if (
    $fp) {
        
    $text fread ($fpfilesize ($filename));
        
    fclose ($fp);
        echo 
    $text;
    }
    else {
        echo (
    "File is not readable");
    }

    ?>

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
  •  
HTML5 Development Center



Recent Articles