feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am not sure exactly what you are trying to do. Are you trying to put the contents of the "mysql_fetch_array" into an array, or are you trying to put the contents of "post.inc"?
anyways what I think you are trying to do is place the fetch data into a string surronded by <h1> tags, so that is what I am going to show you how to do.
Code: Select all
$variable = "";
while ($result = mysql_fetch_array($query))
{
$variable .= "<H1>".$result["row_that_was_fetched"]."</H1>";
}
Now, the only reason I could possibly think you would want to read in the value
Code: Select all
"<H1>".$result["row_that_was_fetched"]."</H1>"
is for easy editing later. So you will need to use fopen in order to get that data if that is where you want to store it. So try this:
First off make the contents of 'post.inc' equal to:
Code: Select all
"<H1>".$result["row_that_was_fetched"]."</H1>";
1) You are inside of a php tag, you can not have html tags just hanging around.
2) You can NOT have those php tags in there since you are already in a php tag. If those have to stay, you will have to do some string manip and parse them out of $fileContent after the file is read in.
3) Second get rid of that print command, that is going to put the output to the screen, but you want the output in a variable. Again if that is required you are going to need to parse that out.
Now using our new post.inc try the code below.
Code: Select all
$inFile = fopen('post.inc', 'r');
$fileContent = fread($inFile, filesize('post.inc'));
fclose($inFile);
//put parser code here if needed.
$variable = "";
while ($result = mysql_fetch_array($query))
{
$variable .= eval("return ".$fileContent);
}
The code above will evaluate the file, and return the parameters as a string.
You are lucky I am feeling generous so I will show you the code to convert A) into B)
A)
Code: Select all
<h1><?php print $result['row_that_was_fetched']; ?></h1>
B)
Code: Select all
"<h1>".$result["row_that_was_fetched"]."</h1>";
Code: Select all
$fileContent = str_replace("print ","",$fileContent);
$fileContent = str_replace("<?php ","",$fileContent);
$fileContent = str_replace(" ?>","",$fileContent);
$fileContent = str_replace(";","",$fileContent);
$fileContent = str_replace('<','"<',$fileContent);
$fileContent = str_replace('>','>"',$fileContent);
$fileContent .= ";";
So put it all together and you will have, starting with the 'post.inc' that you submitted:
Code: Select all
$inFile = fopen('post.inc', 'r');
$fileContent = fread($inFile, filesize('post.inc'));
fclose($inFile);
$fileContent = str_replace("print ","",$fileContent);
$fileContent = str_replace("<?php ","",$fileContent);
$fileContent = str_replace(" ?>","",$fileContent);
$fileContent = str_replace(";","",$fileContent);
$fileContent = str_replace('<','"<',$fileContent);
$fileContent = str_replace('>','>"',$fileContent);
$fileContent .= ";";
$variable = "";
while ($result = mysql_fetch_array($query))
{
$variable .= eval("return ".$fileContent);
}
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]