Jump to content

Filtering with multiple variables


surfsup

Recommended Posts

Newbie so bare with me. trying to filter a recordset with 2 variables submitted from a form. i.e.

 

If user selects dropdown the results will be filtered by that value alone. If user selects value from both results filtered by both values

 

This works fine for one

 

<?php $colname_rs_Results = "%";
if (isset($_GET['v_sleeps'])) {
  $colname_rs_Results = $_GET['v_sleeps'];
}
$colname2_rs_Results = "%";
if (isset($_GET['v_location'])) {
  $colname2_rs_Results = $_GET['v_location'];
}?>

<?php mysql_select_db($database_FireFly, $FireFly);

$result = mysql_query("SELECT * FROM ff_villas
WHERE v_sleeps = $colname_rs_Results");

while($row = mysql_fetch_array($result))
  {
  echo $row['v_name'] ;
  echo "<br />";
  }

?>

 

 

but this gives me errors

 

 

<?php $colname_rs_Results = "%";
if (isset($_GET['v_sleeps'])) {
  $colname_rs_Results = $_GET['v_sleeps'];
}
$colname2_rs_Results = "%";
if (isset($_GET['v_location'])) {
  $colname2_rs_Results = $_GET['v_location'];
}?>

<?php mysql_select_db($database_FireFly, $FireFly);

$result = mysql_query("SELECT * FROM ff_villas
WHERE v_sleeps = $colname_rs_Results AND v_country = $colname_rs_Results");

while($row = mysql_fetch_array($result))
  {
  echo $row['v_name'] ;
  echo "<br />";
  }

?>

 

I hope that makes sense if not the greates tbit of coding ever seen

Link to comment
https://forums.phpfreaks.com/topic/133667-filtering-with-multiple-variables/
Share on other sites

Not sure but would the colname_rs_results actually be colname2_rs_results? If so, your script would be slightly modified to the following:

 

$result = mysql_query("SELECT * FROM ff_villas
WHERE v_sleeps = $colname_rs_Results AND v_country = $colname2_rs_Results");

 

If not, what is the exact error that you are getting?

Yes you are correct. I switeched that but still get this error

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\home\Default\fireflylodges.com\htdocs\property.php on line 17

 

line 17 being

 

while($row = mysql_fetch_array($result))

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.