Page 1 of 1

formatting the text that's saved to a file in PHP

Posted: Thu Apr 22, 2004 12:15 am
by psiege
Well, I'm gathering some info from my db with a query and then outputting the results to a file. I have successfully gathered all of the information for the files and printed the info to them, the only problem is that it just kind of bunches it all together. I need to seperate each result on its own line and even include two of the results on the same line with an "=" between the two of them. If someone can generally guide me on how to format the text output, it would be very helpful.

Here is a snipit of the code i'm currently using:

$sql = "SELECT
c.components_name,
s.subsection_name,
psk.key_name,
ps.parameter_settings_value,
psk.key_description
FROM
parameter_settings ps
INNER JOIN
components c
ON
ps.components_id = c.components_id
INNER JOIN
subsections s
ON
ps.subsection_id = s.subsection_id
INNER JOIN
parameter_settings_key psk
ON
ps.key_id = psk.key_id
WHERE
ps.configuration_id = $configuration_name AND ps.components_id = $value";


$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)){
foreach ($row as $fileValue){
print "$fileValue<br>";

fputs($fp, $fileValue);

}
}

fclose($fp); //closes the file being written to

Thanks to all in advance!

Chris

Posted: Thu Apr 22, 2004 12:50 am
by Chris Corbyn

Code: Select all

while ($row = mysql_fetch_assoc($result)){ 
foreach ($row as $fileValue){ 
print "$fileValue<br>"; 

fputs($fp, "".$fileValue."\r\n"); 

} 
}
Should create a new line after each row. I'll have a think about the "=" .

Posted: Thu Apr 22, 2004 6:39 am
by magicrobotmonkey
Hoe do you know which ones should be on the same line? Are they always in the same location or at least one of them has the same value?

Posted: Thu Apr 22, 2004 6:42 am
by JAM