I'm building a web page that gets information from a mySQL database. It's setup like this:
<?php
if ($act == "") {
//// Get the index page
$myQuery = "SELECT *
FROM $menu
WHERE control='index' ";
$result = $dbh->prepare($myQuery);
$result->execute();
while($row = $result->fetch()){
$page = $row['title'];
$myQuery = "SELECT *
FROM $content_main
WHERE title='$page' ";
$result = $dbh->prepare($myQuery);
$result->execute();
while($row = $result->fetch()){
echo ''.$row['content'].'';
}
}
}
//// Get the link
if ($act == view && $title == $title) {
$req=addslashes($title);
$myQuery = "SELECT *
FROM $menu
WHERE title='$req'
ORDER BY title ASC ";
$result = $dbh->prepare($myQuery);
$result->execute();
while($row = $result->fetch()){
//// Get the users pages
if ( $row['control'] == 'users' ) {
$myQuery = "SELECT *
FROM $users
WHERE title='$req' ";
$result = $dbh->prepare($myQuery);
$result->execute();
while($row = $result->fetch()){
$content = $row['content'];
echo ''.$content.'';
}
}
//// Get the content pages
else {
$myQuery = "SELECT *
FROM $content_main
WHERE title='$req' ";
$result = $dbh->prepare($myQuery);
$result->execute();
while($row = $result->fetch()){
$content = $row['content'];
echo ''.$content.'';
}
}
}
}
include("includes/test-bottom.php");
?>
The links that call the page ; <a href="?act=view&title=".$row['title'].""\">".$row['title']."</a>
Now the only way I know how to get this to work is using extract($_REQUEST, EXTR_SKIP);
, but I've heard this is bad. I've also heard if done right, it's OK. What I can't seem to do is come up with or find a good alternative (I've tried fetch() ,"foreach" ). Is there a way to do this without it? OR a good way?