FUNKAM35 Posted February 24, 2014 Share Posted February 24, 2014 .php?order_by=pricedesc&submit=go <a href=\"".$_SERVER['PHP_SELF']."?country=$country\"> <?php echo "<table width=\"40%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\"> <tr><td class=\"norm\" align=\"left\"> <div class=\"styled-select\"> <form id=\"formorder\" action=\"$_SERVER[PHP_SELF].?country=$country\" method=\"get\"> <select name=\"order_by\" onChange=\"UpdateQty(this)\" > <option value=\"sort by\" selected=\"selected\">Sort by</option> <option value=\"rate3asc\">Lowest Price First</option> <option value=\"rate3desc\">Highest Price First</option> <option value=\"newest\">Recently Added</option> <option value=\"bedsasc\">Beds (Low to High)</option> <option value=\"bedsdesc\">Beds (High to Low)</option> <input type=\"submit\" name=\"submit\" id=\"button\" value=\"go\"> </form></div></td><td class=\"norm\" align=\"left\">\n"; if($order_by=="rate3asc"){ echo"Sorted by Lowest Price First"; } if($order_by=="rate3desc"){ echo"Sorted by Highest Price First"; } if($order_by=="newest"){ echo"Sorted by Recently Added Properties First"; } if($order_by=="bedsasc"){ echo"Sorted by Least Bedrooms First"; } if($order_by=="bedsdesc"){ echo"Sorted by Most Bedrooms First"; } echo"</tr></td></table>\n"; ?> Hi, I am using the following script to order results but he problem is that the page in its normal pagination includes the variable $country, I cannot get the order to include the $country variable, it just goes to order_by=beds_desc and ignores the country so dispalys no results, please help Thanks ina dvance Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/ Share on other sites More sharing options...
Zane Posted February 24, 2014 Share Posted February 24, 2014 I do not see anywhere in your code where you actually use the $_GET['country'] variable. Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470457 Share on other sites More sharing options...
Psycho Posted February 24, 2014 Share Posted February 24, 2014 Also, looking at this, it appears you want the country value to persist from page to page. If so, passing on the query string will add complication. It would be better to save it within the session or a cookie. Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470462 Share on other sites More sharing options...
mac_gyver Posted February 24, 2014 Share Posted February 24, 2014 when you use a method='get' form, ONLY the form fields are passed on the end of the url when the form is submitted. you will need to pass the country as a hidden field in the form. Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470463 Share on other sites More sharing options...
FUNKAM35 Posted February 24, 2014 Author Share Posted February 24, 2014 if($_GET['order_by']=='rate3asc')$order="order by rate3 ASC "; if($_GET['order_by']=='rate3desc')$order="order by rate3 DESC "; if($_GET['order_by']=='bedsasc')$order="order by beds ASC "; if($_GET['order_by']=='bedsdesc')$order="order by beds DESC "; thanks how do I do this so it retains the country, the other code is Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470464 Share on other sites More sharing options...
FUNKAM35 Posted February 24, 2014 Author Share Posted February 24, 2014 confused.com Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470465 Share on other sites More sharing options...
Psycho Posted February 24, 2014 Share Posted February 24, 2014 thanks how do I do this so it retains the country, the other code is You've never shown how $country is set or how it is used. Is this something that should persist for the user for the entire visit? If so, save the value in the session or a cookie. If it is something they will set for some output but may change during their visit, use a hidden field to ensure it gets passed with the form data (although I would probably still use session data for it). Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470468 Share on other sites More sharing options...
QuickOldCar Posted February 24, 2014 Share Posted February 24, 2014 I was just gonna write what Psycho just wrote, use some sort of geolocation script, or a dropdown in the form with your desired countries. Besides not having anything as a GET value for country visible in this code I always like to check if any or all parameters are actually set in the url or create default values if not I wouldn't use spaces as the parameters name, you have "sort by", instead use "sort_by" if(!isset($_GET['sort_by']) || trim($_GET['sort_by']) == ''){ $sort_by = "newest"; } consider using a switch or an if/elseif/else versus all the if's Example using a switch: switch ($sort_by){ case "rate3asc": echo "Sorted by Lowest Price First"; break; case "rate3desc": echo "Sorted by Highest Price First"; break; case "newest": echo "Sorted by Recently Added Properties First"; break; case "bedsasc": echo "Sorted by Least Bedrooms First"; break; case "bedsdesc": echo "Sorted by Most Bedrooms First"; break; } Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470470 Share on other sites More sharing options...
QuickOldCar Posted February 24, 2014 Share Posted February 24, 2014 (edited) To continue with what I said... Now remove that country=$country from the form and also hyperlink, treat it as this. if(!isset($_GET['country']) || trim($_GET['country']) == ''){ $country = "us"; } Edited February 24, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470471 Share on other sites More sharing options...
Zane Posted February 24, 2014 Share Posted February 24, 2014 Where are you planning to use the $country variable? From what I understand from your posts, you want to use it in your query, which have yet to see. In that case, country should be used in the WHERE clause of the SQL query. Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470473 Share on other sites More sharing options...
FUNKAM35 Posted February 25, 2014 Author Share Posted February 25, 2014 ACTION=\"$_SERVER[PHP_SELF] include_once("db/variables.php"); include_once("admin/functions.php"); register_globals($_POST); register_globals($_GET); connectdb(); $link_id = mysql_connect("$db_host","$db_user","$db_password"); if (mysql_select_db("$db_database", $link_id)); $select="SELECT country from countries order by country asc"; $results = mysql_query("$select", $link_id); $country=$_GET[country]; $select = "SELECT country FROM rental WHERE country='$country'" ; $results = mysql_query("$select", $link_id); while ($query_data = mysql_fetch_row($results)) { $country=trim($query_data[0]); } $where= "country = '$country'"; basically its losing the $country variable which is obtained here when Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470585 Share on other sites More sharing options...
FUNKAM35 Posted February 25, 2014 Author Share Posted February 25, 2014 action=\"$_SERVER[PHP_SELF]country=$country&\" LEADS TO page.phpcountry=Austria&?order_by=3&submit=go page.php?order_by=3&submit=go this is when just action=\"$_SERVER[PHP_SELF]\" <?php echo"<form id=\"formorder\" action=\"$_SERVER[PHP_SELF]\" method=\"get\"> <select name=\"order_by\" onChange=\"UpdateQty(this)\" class=\"dropdown\"> <option value=\"1\">price Acending</option> <option value=\"2\">price Decending</option> <option value=\"3\">Newest First</option> <option value=\"4\">Oldest First</option> <input input type=\"submit\" name=\"submit\" value=\"go\"> </form>\n"; ?> Update been trying all sorts Basically if I put just server self in it takes me to the order by and loses the $country If I try the second code with the $country variable on the server self it puts the ? in the wrong place but keeps the variable and country bit and keeps the order by but the page doesn't exist due to incorrect placement of the ? Please help Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470595 Share on other sites More sharing options...
Psycho Posted February 25, 2014 Share Posted February 25, 2014 You need to stop and understand what you are doing. You were informed why putting country on the URL was not being passed previously. It was because you had a FORM and you set the form method to GET - so the browser was overriding the URL parameters set in the action property with the form field data. Now, based on your last post, you are not including country in the form page at all and are apparently expecting it to be magically available on the processing page. You still never answered my questions. What is the purpose of the country value? Is it something that should persist for the user across all sessions, just the current session, or is it something that the user would need to change during a session. Only by answering those questions can we provide a good solution. Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470623 Share on other sites More sharing options...
FUNKAM35 Posted February 25, 2014 Author Share Posted February 25, 2014 Hi Psych thank you for explaining it. The country is only needed for this page so only for this session Thank you Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470665 Share on other sites More sharing options...
Solution FUNKAM35 Posted February 26, 2014 Author Solution Share Posted February 26, 2014 session_start(); if(!empty($_GET['country']))$_SESSION['country']=$_GET['country']; finally got this to work using this code thanks Quote Link to comment https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/#findComment-1470749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.