Using URL parameters in MYSQL search

前端 未结 4 1466
广开言路
广开言路 2021-01-26 08:03

I am trying to built a search page for products in which i have two table products and inventory, i have my product details in product and inventory details like color,size,pric

4条回答
  •  一向
    一向 (楼主)
    2021-01-26 08:17

    Yes, you are in the right path. Get the values from url using get or request

    $category=mysql_real_escape_string($_GET['cat']);
    $color=mysql_real_escape_string($_GET['color']);
    

    and make your SQL as

    SQL="SELECT p.product_name, p.product_sku, p.product_desc, i.inventory_color, i.inventory_size
    FROM products as p
    INNER JOIN  invetory as i ON p.product_id = i.product_id
    WHERE p.product_category='".$category."' AND i.inventory_color='".$color."'";
    

提交回复
热议问题