Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Creation Problem

    I am trying to create an html file with all my categories listed one per line. The problem is my code is only creating the file with the very first category and that is it. Here is what I have so far:

    PHP Code:
    //Database stuff above here //

    $cat "
    $row[category_name]<br>
    "
    ;

    // Create The Categories File
    $fp fopen("categories.html"'a');
    chmod("categories.html"0777);
    fwrite($fp$cat);
    fclose($fp); 

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    620
    Thanks
    0
    Thanked 6 Times in 6 Posts
    you really should post more of your code.

    looks like you want something along the lines of:

    PHP Code:
    $cat "";    //initialize the category string to nul

    // database stuff
    foreach ($row as mysql_fetch_assoc($result) {

    $cat .= $row["category"];

    }

    // write to file 
    -Celt

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That didn't work for me... Here is my entire code:

    PHP Code:
    include("config.php");

    // Query DB Here
    $result mysql_query("select * from TABLE LIMIT 5") or die (mysql_error()); 
    while (
    $row mysql_fetch_array($result))
    {

    $cat "$row[category_name]<br>";

    // Create Categories File
    $fp fopen("categories.html"'a');
    chmod("categories.html"0777);
    fwrite($fp$cat);
    fclose($fp);

    }
    mysql_free_result($result); 

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hey,

    the reason you are only getting on cat is becuase you are trying to write to your html file inside the while loop... end the loop and then print the $cat to the print

    Sir P


  •  

    Posting Permissions

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