Link to home
Start Free TrialLog in
Avatar of hasozduru
hasozduru

asked on

Extending query according to changes at address bar

Hi Guys

Let say we have http://www.mydomain.com/product.php?cpu=133mhz at address bar and our query is select * from product_table where cpu=133mhz and link which shows cpu, ram, price. When user clicks to ram, address bar will change to http://www.mydomain.com/product.php?cpu=133mhz&ram=512mb and query will be select * from product_table where cpu=133mhz AND ram=512mb. So I will help user to select his item which is best for him. I would like to get logic of adding &ram=512 to the end of address bar and add AND ram=512 to the end of query. What would your suggestion be?

Kind regards
Avatar of dKasipovic
dKasipovic

Try to use drop down boxes in a form. When the link is &cpu=500mHz the drop down box named cpu will show 500MhZ then u put another drop box called ram and let user choose how much ram they want... and so on...
You would need to code it all, but that's not too hard, and neither is too big. If you need url to show parameters, set form method to GET, otherwise set it to POST...
If you need further help on programming the actual site, let me know...
Hope I helped.
Avatar of hasozduru

ASKER

dKasipovic, I don't want to use drop down boxes.

Thanks
SOLUTION
Avatar of gruntar
gruntar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok

How would you do for the following code.

<?
include("dbconnect.php");

$sql = mysql_query("select * from spec_palmtop group by first_field");
echo '<table border=1>';
echo '<td><table border=1>';
while ($row = mysql_fetch_object($sql)) {
      echo "<tr><td><a href=\"" . $_SERVER["PHP_SELF"] . "?first_field=" . $row->first_field . "\">$row->first_field</a></td>";
}

echo '</tr></table>';
$sql2 = mysql_query("select * from spec_palmtop group by second_field");
echo '<td><table border=1>';
while ($row2 = mysql_fetch_object($sql2)) {
      echo "<tr><td><a href=\"" . $_SERVER["PHP_SELF"] . "?second_field=" . $row2->second_field . "\">$row2->second_field</a></td>";
}
echo '</table>';
echo '</table>';
?>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gruntar

Please go to http://dealtime.co.uk/xPP-Personal_Organisers and see Price Range: Brand: Operating System: . I would like to do filtering like that. I cannot do it like your above example.

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No  gruntar, I am not looking for numbers side by brands. Try the following code and see how it works. I need something like that.

Thanks


<?
include("dbconnect.php");
$URL = $HTTP_SERVER_VARS['REQUEST_URI'];

$sql = mysql_query("select * from spec_palmtop group by first_field");
echo '<table border=1>';
echo '<td><table border=1>';
while ($row = mysql_fetch_object($sql)) {
      $link = "<tr><td><a href=\"" . $URL;
      if(!preg_match("/\?/",$URL))
        $link .="?";
      else
        $link .="&";
      $link .="first_field=" . $row->first_field . "\">$row->first_field</a></td>";
      echo $link;
}

echo '</tr></table>';
$sql2 = mysql_query("select * from spec_palmtop group by second_field");
echo '<td><table border=1>';
while ($row2 = mysql_fetch_object($sql2)) {
      $link = "<tr><td><a href=\"" . $URL;
      if(!preg_match("/\?/",$URL))
        $link .="?";
      else
        $link .="&";
      $link .="second_field=" . $row2->second_field . "\">$row2->second_field</a></td>";
      echo $link;
}

echo '</table>';
echo '</table>';

if($first_field and !$second_field) {
  $q_list = mysql_query("select * from product, spec_palmtop where product.category = 1 and product.product_id = spec_palmtop.product_id and first_field = '$first_field'");
}
elseif (!$first_field and $second_field) {
  $q_list = mysql_query("select * from product, spec_palmtop where product.category = 1 and product.product_id = spec_palmtop.product_id and second_field = '$second_field'");
}
elseif ($first_field and $second_field) {
  $q_list = mysql_query("select * from product, spec_palmtop where product.category = 1 and product.product_id = spec_palmtop.product_id and first_field = '$first_field' and second_field = '$second_field'");
}
else{
  $q_list = mysql_query("select * from product, spec_palmtop where product.category = 1 and product.product_id = spec_palmtop.product_id");
}
while ($q_row = mysql_fetch_object($q_list)) {
      echo "$q_row->p_name<br>";
}

?>
I cannot run your code... would have to create tables....

So, you are checking if there is query string in url? You have problems with double variables?

You don't have to use preg_match just use

if(empty($_SERVER['QUERY_STRING'])) {
// ?
} else {
// &
}

...so tell me where the problem is