cinos11 Posted June 8, 2010 Share Posted June 8, 2010 I have a website that displays urls in the form of website.com/index.php?p=home It was created using switches inside the index page with the following code: <?php $page = (isset($_GET['p'])) ? $_GET['p'] : ''; switch($page) { case 'home': include('inc/page/inc1.php'); echo 'Home'; include('inc/page/inc2.php'); include('page/home.php'); include('inc/page/inc3.php'); break; default: include('inc/page/inc1.php'); echo 'Home'; include('inc/page/inc2.php'); include('page/home.php'); include('inc/page/inc3.php'); } ?> My problem is to be able to use a mysql database to list all case's without having to edit the php directly. The thing i have tried is something like this: <?php $page = (isset($_GET['p'])) ? $_GET['p'] : ''; switch($page) { $conn; /* Connect to the server variable */ $dbtests; /* Connect to the database variable */ $result = mysql_query("SELECT * FROM page"); while($row = mysql_fetch_array($result)) { case $row['case']: include('inc/page/inc1.php'); echo $row['title']; include('inc/page/inc2.php'); include('$row['path']'); include('inc/page/inc3.php'); break; } default: include('inc/page/inc1.php'); echo 'Home'; include('inc/page/inc2.php'); include('page/home.php'); include('inc/page/inc3.php'); } ?> and the only problem is i can't get it to work with a while statement in it. It also has trouble by giving the error of unexpected case for the one in the while statement. Anyone know how i can achieve this? Link to comment https://forums.phpfreaks.com/topic/204145-php-page-mysql-include-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.