"Including" files based on mySQL database entries?
Posted: Sun Jul 18, 2010 3:39 am
Hi, I have a mySQL database (and table) which lists several things about some films: name, rating, genre etc. The entries under "name" correspond to .php files which have reviews in them eg thesixthsense in the table will correspond to the file /reviews/thesixthsense.php. What I am trying to do is "include" the files based on the names in the table. So, for instance, if I had The Sixth Sense, Napoleon Dynamite and Fargo listed in my table, I want to be able to "include" the reviews based on the fact that the files and entries have the same names. I hope I'm making sense here! 
If there is a way of doing this, then it means I'll be able to have pages listing just one genre, or only the films I've rated, say, 9 or 10. I've managed to print the actual path of the reviews (see below), but am stuck here. Any help will be much appreciated, as I am still quite new to PHP.
If there is a way of doing this, then it means I'll be able to have pages listing just one genre, or only the films I've rated, say, 9 or 10. I've managed to print the actual path of the reviews (see below), but am stuck here. Any help will be much appreciated, as I am still quite new to PHP.
Code: Select all
<?php
$con = mysql_connect("localhost","myuser","mypass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
$result = mysql_query("SELECT * FROM films");
while($row = mysql_fetch_array($result))
{
print "/reviews/" . $row['name'] . ".php";
print "<br/>";
}
mysql_close($con);
?>