I've been trying to make dynamic queries, where the user determines what will be queried. The reason is because I'd like the images being displayed in my gallery reflect the category selected by the user.
mysql_query("SELECT(whatever category they chose) FROM products")
below is the generation of categories as links. (not sure if it is set up for the task)
Your SQL query isn't fileterd to get a set of image from a particular category.
Current: SELECT * FROM products ORDER BY date_added DESC LIMIT 10
Proposed: SELECT * FROM products WHERE category='[USER_SELECTED_CATEGORY]' ORDER BY date_added DESC LIMIT 10
Just a tip though, before running an SQL query in your application dynamically, be sure it runs well with preloaded data or check it first for erros.
Let's first find if you can query this. SELECT * FROM products WHERE category='[USER_SELECTED_CATEGORY]' ORDER BY date_added DESC LIMIT 10
Be sure that the category you put there exists in your database. And there are products assigned in your selected category. So a sample SQL command you can run with the table below:
QUERY: SELECT * FROM products WHERE category='bags' ORDER BY date_added DESC LIMIT 10
* This snippet has an issue on this par `ESC LIMIT 10"]", $_GE`
* you should make it like this `ESC LIMIT 10", $_GE`
* if your formatting your string you can check the one below from your code
$sql = mysql_query("SELECT * FROM products WHERE category='%s' ORDER BY date_added DESC LIMIT 10"]", $_GET["selectcat"]);
// You can format it like this.
// you can even put the sprintf inside the mysql_query
// if that's your style
$formattedQuery = sprintf("
$sql = mysql_query($formattedQuery);
lol that wasn't in my code, I swear. I must have copied and pasted in a hurry.
I'm going to try your method now. Also, do you think I should just make a "landing page" for my products page since I will not have an active query with this code upon loading the page? I was thinking that's probably the best option because I don't know how to have a default query which I can then have updated when the user selects a new category.