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?

When you pass the data to a script via a URL - ex: <a href="?act=view&title=".$row['title'].""\">".$row['title']."</a> OR via a <FORM> set to get - ex: <form method="get"...> then on the server you should make use of $_GET['variableName'] to extract the data you want/need.

To clarify, given the URL you posted then:

echo $_GET['act'];//should give you view
echo $_GET['title']//should give you whatever $row['title'] had

So, without the use of extract(), line 1 should be: if ($_GET['act'] == "") { likewise, line 24 should be: if ($_GET['act'] == 'view' && $_GET['title'] == $title) {

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.