snnbbc Posted November 7, 2009 Share Posted November 7, 2009 Hello, I would like to ask if anyone knows how to output the following php code into a text file. The code is inside the body tags of an html page. I know that with the fwrite(); function I can save a variable to a text file, but in this code I have a while statement which can output several lines of code. I would like to save the output from the while statement and the $total to the text file. Here is the code: <?php $cnt = array(); $products = array(); foreach($_POST as $key=>$value) { $key=(int)str_replace('_cnt','',$key); $products[]=$key; $cnt[$key]=$value; } $result = mysql_query("SELECT * FROM internet_shop WHERE id IN(".join($products,',').")"); if(!mysql_num_rows($result)) { echo '<h1>There was an error with your order!</h1>'; } else { echo '<h1>You ordered:</h1>'; while($row=mysql_fetch_assoc($result)) { echo '<h2>'.$cnt[$row['id']].' x '.$row['name'].'</h2>'; $total+=$cnt[$row['id']]*$row['price']; } echo '<h1>Total: $'.$total.'</h1>'; } ?> Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted November 7, 2009 Share Posted November 7, 2009 do you want the output of the php saved as a text file or the actual php code? If you want the php code saved and you need your post variables. You'd have to serialize post. Then unserialize it in your code. If you just need to output. Then assign the output to a variable and write that to a text file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.