Jump to content

Trying to add two different selects for same field but different purposes


FUNKAM35
Go to solution Solved by FUNKAM35,

Recommended Posts

$where= " province = '$province' ";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num  FROM rental  WHERE  $where "),0) ;

<?php
$country=$_GET[country];
$province_numbers=array();
$additional = array();
$select="SELECT distinct province FROM rental WHERE country = '$country' order by province asc "; 
$results = mysql_query("$select", $link_id);
if(mysql_num_rows($results)>0){
 while ($query_data = mysql_fetch_row($results))
 {
$province=$query_data[0];
if(trim($province==""))continue;
$province=stripslashes($province);
echo "<li><a href=\"rentals.php?province=$province&country=$country\" title='$province $country'>$province</a></li>\n";
}
}
?>

Hi, I am trying to add the code above as an include.

 

However it conflicts with the main select on the page printed first above

 

Basically the page is listing all properties in one province, which works fine

 

but when I try and add the include it lists all the provinces but wont select the main province the page is about, it lists properties from the last province in the include not from the province in the where!

 

Hope this is clear I know what I mean

Many thanks in advance

 

Link to comment
Share on other sites

When renaming the variable, you are not changing its value. The value will still be the same.

 

The problem is the $province variable used in your include is overriding the $province variable used in the parent file. To prevent this you need to rename the $province variable used in the include file.

 

This will be the code for the include, with the $province variable being renamed to $theProvince

<?php
$country=$_GET[country];
$province_numbers=array();
$additional = array();
$select="SELECT distinct province FROM rental WHERE country = '$country' order by province asc "; 
$results = mysql_query("$select", $link_id);
if(mysql_num_rows($results)>0){
 while ($query_data = mysql_fetch_row($results))
 {
$theProvince=$query_data[0];
if(trim($theProvince==""))continue;
$theProvince=stripslashes($theProvince);
echo "<li><a href=\"rentals.php?province=$theProvince&country=$country\" title='$theProvince $country'>$theProvince</a></li>\n";
}
}
?>

The $province variable used in the parent file will not be affected by the code in the include file.

Edited by Ch0cu3r
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.