erme Posted August 13, 2009 Share Posted August 13, 2009 Thought this was best suited as a new topic rather then a string of multiple questions in a topic that the title wasn't now true to. I have 2 files, index.php and locations.php. In index.php I have $extrapart = (isset($_GET['county'][0]))?"WHERE County='".mysql_real_escape_string($_GET['county'])."'":""; and in locations.php $query = "SELECT * FROM locations $extrapart"; $result = mysql_query($query); In order for what I am wanting, I have my URL like this /index.php?county=devon however because this is being called in index.php, I can't use $extrapart in locations.php. Is there a way locations.php can read this? Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/ Share on other sites More sharing options...
DEVILofDARKNESS Posted August 13, 2009 Share Posted August 13, 2009 you can store it in a session, or in a cookie Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897296 Share on other sites More sharing options...
erme Posted August 13, 2009 Author Share Posted August 13, 2009 Know of any good tutorials on this? Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897315 Share on other sites More sharing options...
Batosi Posted August 13, 2009 Share Posted August 13, 2009 <?php $_SESSION['extrapart'] = (isset($_GET['county'][0]))?"WHERE County='".mysql_real_escape_string($_GET['county'])."'":""; $query = "SELECT * FROM locations $_SESSSION[extrapart]"; ?> Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897334 Share on other sites More sharing options...
erme Posted August 13, 2009 Author Share Posted August 13, 2009 <?php $_SESSION['extrapart'] = (isset($_GET['county'][0]))?"WHERE County='".mysql_real_escape_string($_GET['county'])."'":""; $query = "SELECT * FROM locations $_SESSSION[extrapart]"; ?> Dosen't seem to work Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897363 Share on other sites More sharing options...
DEVILofDARKNESS Posted August 13, 2009 Share Posted August 13, 2009 ofcourse, it should be: $query = "SELECT * FROM locations $_SESSION['extrapart']"; and if that doesn't work: $extrapart = $_SESSION['extrapart']; $query = "SELECT * FROM locations $extrapart"; BTW don't forget to include as first line above the html in your php: session_start(); And I think something is wrong with your query: SELECT * FROM locations $extrapart what should the variable extrapart contain? Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897379 Share on other sites More sharing options...
erme Posted August 13, 2009 Author Share Posted August 13, 2009 $extrapart = (isset($_GET['county'][0]))?"WHERE County='".mysql_real_escape_string($_GET['county'])."'":""; so it will be something like ?county=devon Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897620 Share on other sites More sharing options...
mikesta707 Posted August 13, 2009 Share Posted August 13, 2009 in index.php $extrapart = (isset($_GET['county'][0]))?"WHERE County='".mysql_real_escape_string($_GET['county'])."'":""; $_SESSION['extra'] = $extrapart;//or just set the session var to the above then in your locations page either use the session var or set the variable to the session var's value. also, I don't know if you want to select everything from your database if the county isn't set, but currently your script will only select entries of a certain county if it's set, and everything from the table if the county isn't set. you may want to change this if this isn't desired Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897628 Share on other sites More sharing options...
erme Posted August 13, 2009 Author Share Posted August 13, 2009 then in your locations page either use the session var or set the variable to the session var's value. Sorry I don't understand Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897632 Share on other sites More sharing options...
mikesta707 Posted August 13, 2009 Share Posted August 13, 2009 ... in $query = "SELECT * FROM locations $extrapart"; $result = mysql_query($query); instead of extrapart variable, use the session variable (in my code's case, $_SESSION['extra']) or set the $extrapart variable to $_SESSION['extra'] Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897633 Share on other sites More sharing options...
erme Posted August 13, 2009 Author Share Posted August 13, 2009 So it will be $query = "SELECT * FROM locations $extra"; $result = mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897637 Share on other sites More sharing options...
erme Posted August 13, 2009 Author Share Posted August 13, 2009 Whata star!!! Thanks .. it works! Link to comment https://forums.phpfreaks.com/topic/170095-solved-2-files-url-and-variable-problem/#findComment-897640 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.