As a new project I recently tried creating a webshop just to see how it works. I already display all the new items which are on sale in the main div using php and a select tag. And I'm also able to only display items from a certain category when the user clicks on a category in the sidebar. When the user clicks the sidebar the page is reloaded but to the url it adds ?category=car or some other category. After that I use $_GET['
if(isset($_GET['category'])){
$testsearch = htmlspecialchars($_GET['category']);
$sqlselect = "SELECT * FROM items_sale INNER JOIN item_list ON items_sale.item_id = item_list.item_id INNER JOIN user_list ON items_sale.user_id = user_list.user_id INNER JOIN categories ON items_sale.categorie_id = categories.category_id where category = '$testsearch'";
}else{
$sqlselect = "SELECT * FROM items_sale INNER JOIN item_list ON items_sale.item_id = item_list.item_id INNER JOIN user_list ON items_sale.user_id = user_list.user_id INNER JOIN categories ON items_sale.categorie_id = categories.category_id";
}
What I can't seem to get to work is to also add something like a search bar where the user can search for the seller's name or the name of a item while staying within the selected category.
Is there a simple way to do this? Because I can only think of a bunch of If statements within each other to see what option is selected. Also if there are better options for a simple search system like this or more secure thats fine to of course. This is just how I've been doing it so far
Here is a screenshot of my current table btw
firstly, i recommand you to don't put chars in an url, but id. It's safer, simplier and no error with url encoding or else. And you just have to cast the id you get. It will be quicker too to search in mysql database with an id than a string :)
For your question, you can put your category name (or id :) ) in a form with an input hidden.
Example :
<form>
<input type="text" id="seller_name">
<input type="hidden" id="category" value="<?php echo (int)$_GET['category']?>">
</form>
On your server side, when you receive the request, you check category and seller's name in your sql request (with 2 if for example...)