Help with Where SQL using dropdown filter

Lucien_VRN 10 Sep, 2013
Just after a bit of help or advice. I've set up a pricing table using different currencies and want to use a dropdown on the front end for the site visitor to select the currency they use, so that only one price table shows.

I used a CF to upload all the differen rates (just 3 for now, gbp, usd and eur) then created a CC to display the table on the website. All of this works fine and I can display either a table with all currencies (with no statement in WHERE) or, if I include currency='gbp' for example then I get the table with just gbp showing.

The bit I can't fully figure out is how to get the variable from the select dropdown back into the WHERE box. Here is what I've got so far:
HEADER
<table>
  <thead>
<tr>
</tr>
    <tr>
<html>
<body>
  <form action="<?php $_PHP_SELF ?>" method="GET">
      <th>Select Your Currency</th><th>
<div>
<select name=tempselect size="1">
<option value="USD">USD</option>
<option value="EURO">EUR</option>
<option value="GBP">GBP</option>
</select>
<input type="submit" value="Submit" />
</form>
<?php
global $tempselect;
?>
</body>
</html>
</div></th></tr>
<tr></tr>
<tr><th>Description</th><th>Per Night</th><th>Per Week</th>
    </tr>
  </thead>
 <tfoot>
    <tr>
      <td colspan='3' style='background:silver; height:4px;'></td>
    </tr>
  </tfoot>

BODY

<tr><td>{descriptor_1}</td><td>{night}</td><td>{weekly}</td></tr>

FOOTER
</table>


WHERE SQL
<?php
$tempselect = JRequest::getString('tempselect', '', 'get');
 {
  echo "`currency` = '$tempselect' ";
}
?>

Any help or pointers appreciated...you may be able to tell that I'm a bit of a newbie at this!๐Ÿ™‚
GreyHead 10 Sep, 2013
Hi Lucien_VRN,

I've never seen a form added quite like that so can't tell if it will work or not. If it is adding the value to the URL then I think it will probably be available in the WHERE box.

Adding extra <html> and <body> tags is though likely to confuse some browsers and may break the page. You also need to make sure that the CC <form> tags are turned off as you can't nest <form> tags.

Bob
Lucien_VRN 10 Sep, 2013
Thanks for that advice, I took out the extra <html> and <body> tags and also turned off the CC form tags (I did think from the tutorial that it had to be on, but understand what you are saying.
It does now put the selected currency value into the url, I'm only running it on localhost right now but get:
http://localhost/mvillas/index.php?tempselect=EURO
after I've made a selection.

Will play around with it some more but feel I am moving in the right direction๐Ÿ˜€ Any additional comments or help from this helpful community is appreciated.
Lucien_VRN 12 Sep, 2013
That is all working well now with those changes and I can now select different currencies from my dropdown and they display correctly, with the value shown in the url, for example:
http://localhost/mvillas/index.php/booking/rates?selected=USD

The only last bit I don't fully understand is how to get the table to show a default set of results, say for example 'gbp' rates. I've tried using a if else statement to make where = gbp

WHERE SQL
<?php
if (empty($selected)) 
{
$selected='gbp';
}
else
$selected = JRequest::getString('selected', '', 'get');
{
echo "currency = '$selected' ";
}
?>

but that doesn't work. It loads the correct table to start but then doesn't update if a different currency is selected.
GreyHead 16 Sep, 2013
Hi Lucien_VRN,

I really don't understand how you have this set up. I don't think that echo "currency = '$selected' "; will do anything useful. More likely you have to loop through the options and set the selected attribute on one of them.

Bob
This topic is locked and no more replies can be posted.