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

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

Thank you very much conker87 exactly what i was trying to do :) but i didnt try what haku posted, but the if and else if worked.. btw what is the difference between elseif and else if? I used elseif,, and it worked for me

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.