MySQL probs..

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
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

MySQL probs..

Post by Jim »

I've used eval() to get information from a specific page.

Code: Select all

$filename = "/home/empirega/public_html/xg/news/xgn_template.txt";
$handle = fopen ($filename, "r");
$template = fread ($handle, filesize ($filename));
fclose ($handle);
eval("\$template = "$template";");
Works like a charm! The problem is... when I continue on in the SQL code later...

Code: Select all

$fp = fopen("/home/empirega/public_html/xg/news/$site.php","w");

	if($query) {
	
		while ($data = mysql_fetch_assoc($query)) {		
		
			  $subject = $data['subject'];
			  $author = $data['post_by'];
			  $body = $data['post_body'];
			  $date = date("l, F j Y \@ g:i a", $data['post_date']);
			  
			  
			   
$news = $template;
	

			
fputs($fp,$news,strlen($news));
fflush($fp);	

}

fclose($fp);

}
It writes the same information to a file over and over and over... :P

http://www.empiregaming.net/xg/news/xgn.php (what the product is)

Any way to sort of reset the value of $template each time the while statement is run through?

Help is appreciated! Thanks!
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

in each loop cycle you write $news to the file, $news is a copy of $template, I don't see anything in the loop changing $template ??
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

Template is the file xgn_template.txt. It's filled with undefined variables.

Code: Select all

<table>
<tr>
<td><b>$subject</b></td>
</tr>
<tr>
<td>by $author on $date</td>
</tr>
</table>
Apparently they get set in the while loop and don't change as the news goes from post to post. *sigh*

How do I fix that?
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Fixed it...

Post by Jim »

Put the fopen and fread into the loop. Works now! Thanks!
Post Reply