So I’ve got some rows in a table that I want to use to concatenate. I also have a file that runs a query to count comments. I want to pull that number from that file.
I was doing it with straight html but my website is getting too big so I’m trying to make it dynamic with php and mysql.
So with my Html its hard coded and works:
<?php include_once("comments/post_title/tpost_title.php") ?>
So I thought I could just concatenate it to be the same, but for some reason my web browser (chrome) thinks its a comment.
Php:
$query = "SELECT post_title FROM sessions";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo "<a href=\"#" .strip_tags("{$row['post_title']}"). "\">read comment";
echo "<?php include_once(\"comments/" .strip_tags("{$row['post_title']}")."/t". strip_tags("{$row['post_title']}"). ".php\") ?>";
echo "</a>";
}
I’ve read about “@file_get_contents” but my understanding of it is limited. As I understand it has to be set to a variable and then I would have to insert that into my while loop. But I get lost in how the variable changes to the next row in my table to pull the next post_title.
I guess another option would be to put the query that’s in that file that counts comments into this loop, but then I’d have to put a variable into the query. (Is that “good” coding?) Say for instance:
$query = "SELECT post_title FROM sessions WHERE session = 'variable';
Thanks in advance for the help and insight.
To read the file in the loop, you need:
If the file you read isn’t PHP but straight HTML, then you can use readfile() instead of include(). The syntax is the same.
To be sure, though, it would be better something like,