I have a page that needs to make six nearly identical queries with the only difference between them being the value of “category”:
$query = "SELECT * FROM table_name WHERE category="CATEGORY1";
Instead of writing out six different $query variables ($query1, $query2, etc.) for each different category, I’d like to abbreviate so I can pass in category as a variable each time I instantiate $query, like so:
$query = "SELECT * FROM table_name WHERE category='$cat'";
$results= mysql_query($query,'CATEGORY1');
There must be some way to do this, but I simply can’t find the syntax anywhere for passing a variable to a MySQL query in this way (I checked php.net, this site, various other php resources on Google). Can anyone help me out?
Much appreciated, thanks!
You can use
sprintffor that: