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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psiege
Forum Newbie
Posts: 1
Joined: Thu Apr 22, 2004 12:15 am

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

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 "=" .
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Post Reply