Jump to content

[SOLVED] Can this be cleaned up? $_GET and variables


intodesi

Recommended Posts

This may be a mysql questions, but i beleive im in the right area,.

 

ok im trying to get some dynamic'ness to my website, well mostly because google tells me I have duplicate meta descriptions.. I already had a member help me with something that works, but the problem is i have 2 $_GET[]'s that supply the information for the database to retreive the meta data, this is the code i have that is working

 

<?php
include 'pages/scripts/configdb.php';
include 'pages/scripts/opendb.php';
$page1 = $_GET[p];
$page2 = $_GET[c];
$sql = "SELECT * FROM pages WHERE page='$page1' LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

$sql2 = "SELECT * FROM pages WHERE page='$page2' LIMIT 1";
$result2 = mysql_query($sql2);
$row2 = mysql_fetch_assoc($result2);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META NAME="description" CONTENT="<?php echo ("zinto design, $row[mdescr] $row2[mdescr]"); ?> ">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? 
echo ("Zinto Design-- $row[title] $row2[title]");
?></title>

 

as you can see im using to variables for my $_GET

$page1

and

$page2

 

and I am supply those variables to two different sql statements, is there a way I can clean this up and only call sql once, using both page1 and page 2 depending on what is supplied? if not its not a big deal, What i have works, its just dirty. I would like to say something like

 

$page = $_GET[p] or $_GET[c] and use the one which has data associated with it because urls will only have one or the other

 

index.php?p=page or index.php?c=page

but not both

<?php

if ($_GET['p'])
       {
              $page = mysql_real_escape_string($_GET['p']);
       }
else if ($_GET['c'])
       {
              $page = mysql_real_escape_string($_GET['c']);
       }

$sql = "SELECT * FROM pages WHERE page='$page' LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
?>

 

Something like that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.