FUNKAM35 Posted February 22, 2014 Share Posted February 22, 2014 $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 https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/ Share on other sites More sharing options...
Ch0cu3r Posted February 22, 2014 Share Posted February 22, 2014 Rename the variable $province used in your include to a different name Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470050 Share on other sites More sharing options...
.josh Posted February 22, 2014 Share Posted February 22, 2014 sidenote: if(trim($province==""))continue; should be if(trim($province)=="")continue; Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470077 Share on other sites More sharing options...
FUNKAM35 Posted February 23, 2014 Author Share Posted February 23, 2014 Rename the variable $province used in your include to a different nameThanks how do I do this, don't understand thanks Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470237 Share on other sites More sharing options...
Ch0cu3r Posted February 23, 2014 Share Posted February 23, 2014 You find each instance where $province is used in the included file, and then replace it with $new_var_name new_var_name being the new name for the variable of your choosing. That is what I mean by renaming the variable. Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470251 Share on other sites More sharing options...
FUNKAM35 Posted February 23, 2014 Author Share Posted February 23, 2014 I might be thick but how does it then know its selecting tge province? Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470300 Share on other sites More sharing options...
Ch0cu3r Posted February 23, 2014 Share Posted February 23, 2014 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. Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470304 Share on other sites More sharing options...
FUNKAM35 Posted February 23, 2014 Author Share Posted February 23, 2014 fantastic many thanks,will try this, could see the overriding bit but didnt know how to solve it, many thanks,will report back when tried. Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470311 Share on other sites More sharing options...
FUNKAM35 Posted February 24, 2014 Author Share Posted February 24, 2014 woohoo it works many thanks Link to comment https://forums.phpfreaks.com/topic/286411-trying-to-add-two-different-selects-for-same-field-but-different-purposes/#findComment-1470379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.