intodesi Posted May 13, 2008 Share Posted May 13, 2008 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 https://forums.phpfreaks.com/topic/105380-solved-can-this-be-cleaned-up-_get-and-variables/ Share on other sites More sharing options...
haku Posted May 13, 2008 Share Posted May 13, 2008 You can combine your queries like this. SELECT * FROM pages WHERE page = '$page1' OR page='$page2' Link to comment https://forums.phpfreaks.com/topic/105380-solved-can-this-be-cleaned-up-_get-and-variables/#findComment-539719 Share on other sites More sharing options...
conker87 Posted May 13, 2008 Share Posted May 13, 2008 <?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 https://forums.phpfreaks.com/topic/105380-solved-can-this-be-cleaned-up-_get-and-variables/#findComment-539721 Share on other sites More sharing options...
intodesi Posted May 13, 2008 Author Share Posted May 13, 2008 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 https://forums.phpfreaks.com/topic/105380-solved-can-this-be-cleaned-up-_get-and-variables/#findComment-539723 Share on other sites More sharing options...
conker87 Posted May 13, 2008 Share Posted May 13, 2008 else if and elseif are the same, just different spelling. I think it might be for backward compatibility, not too sure. Link to comment https://forums.phpfreaks.com/topic/105380-solved-can-this-be-cleaned-up-_get-and-variables/#findComment-539761 Share on other sites More sharing options...
intodesi Posted May 13, 2008 Author Share Posted May 13, 2008 ok and thanks alot again, was bothering me for a while, i had tried t use if and else if, but wasnt using the right syntax.. Link to comment https://forums.phpfreaks.com/topic/105380-solved-can-this-be-cleaned-up-_get-and-variables/#findComment-539796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.