How to abbreviate MySQL queries in PHP? -
i have page needs make 6 identical queries difference between them being value of "category":
$query = "select * table_name category="category1";
instead of writing out 6 different $query variables ($query1, $query2, etc.) each different category, i'd abbreviate can pass in category variable each time instantiate $query, so:
$query = "select * table_name category='$cat'"; $results= mysql_query($query,'category1');
there must way this, can't find syntax anywhere passing variable mysql query in way (i checked php.net, site, various other php resources on google). can me out?
much appreciated, thanks!
you can use sprintf
that:
$query = "select * table_name category='%s'"; $results= mysql_query(sprintf($query,'category1'));
Comments
Post a Comment