SQL Query Naming / Standards
Posted: Fri Aug 03, 2007 11:37 pm
Well, in my short career of programming in php, I've noticed a few `junk` variables people use when working with sql queries.
Generally 9 times out of 10, if you see a snippet of code, it is more than likely you will see those variables [q, sql, rows] used, and as a result, thats what I use in my code. My question is, what do you use when you have more than one query? Currently I have 3 queries, and I've just added a 2 and 3 to the variables, but it just seems messy and not what you would expect in `good` code.
This is what I currently have:
I was looking into UNION to possibly make it one query, would that be recommended? Other than that, are there any general naming standards for such cases as this?
Code: Select all
$q = "QUERY HERE";
$sql = mysql_query($q);
$rows = mysql_fetch_assoc($sql)This is what I currently have:
Code: Select all
$sql = mysql_query("SELECT * FROM `".$db_prefix."tl_stats` WHERE `cid` = '$randcid'") or die(mysql_error());
$sql2 = mysql_query("SELECT * FROM `".$db_prefix."tl_hits` WHERE `cid` = '$randcid'") or die(mysql_error());
$sql3 = mysql_query("SELECT * FROM `".$db_prefix."tl_users` WHERE `cid` = '$randcid'") or die(mysql_error());
$rows = mysql_fetch_assoc($sql);
$rows2 = mysql_fetch_assoc($sql2);
$rows3 = mysql_fetch_assoc($sql3);