Jump to content

$_SERVER[PHP_SELF] problem


Go to solution Solved by FUNKAM35,

Recommended Posts

.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

Link to comment
https://forums.phpfreaks.com/topic/286489-_serverphp_self-problem/
Share on other sites

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

 

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).

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;    
}

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 by QuickOldCar

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.

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

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 

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.

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.