Home >Backend Development >PHP Tutorial >An example of simplifying SQL statements_PHP tutorial
For example, assume that the table name is bbs, the field of the number of replies is renum, the variable name is $renum, the record number field is id, the variable name is $id
When we reply to a forum post, we will rewrite the number of replies of the main post. The traditional method Two SQL statements are needed:
//Get the original value
$query1="select renum bbs where id = '$id'";
......
$renum;
//Write back to the database
$query2="update bbs set renum = '$renum' where id = '$id'";
The simplified version is as follows:
$query="update bbs set renum = renum 1 where id = '$id'";
All done in one sentence!