...

View Full Version : File Creation Problem



Pee-H-Pee
09-29-2004, 10:28 PM
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:


//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);

Celtboy
09-29-2004, 10:39 PM
you really should post more of your code.

looks like you want something along the lines of:



$cat = ""; //initialize the category string to nul

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

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

}

// write to file


-Celt

Pee-H-Pee
09-29-2004, 10:48 PM
That didn't work for me... Here is my entire 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);

sir pannels
09-30-2004, 02:44 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum