I made a very simple view counter. Ultimately I will convert to a cronjob view counter/updater, but for now I will just use a mysql update query every time the page refreshes. I was wondering if there was any way to turn these 2 statements into one, trying to cut down on processing.
PHP:
$query=mysql_query("SELECT * FROM questions WHERE id='$q'"); //string is escaped (not shown)
while ($row=mysql_fetch_assoc($query)){
$views=$row['views']+1;
}
mysql_query("UPDATE questions SET views='$views' WHERE id='$q'");
Also, it would be really helpful if you could point out potential security issues if you notice any. thanks
Why not just:
This will increase your views by 1.