Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- shortening code
May 13, 2008, 12:10 am
rate this thread
$sql_forum_posts_num = "SELECT forum_posts FROM ".
$db_db.".phpbb_forums WHERE forum_id = '$forum_id'";
$forum_posts_num = mysql_query($sql_forum_posts_num) or
$forum_posts_num_real = mysql_fetch_row($forum_posts_num);
$forum_posts_real_num = $forum_posts_num_real + $num_topics_real;
$forum_topics_num_update_sql = "UPDATE ".$db_db.".phpbb_forums SET
forum_posts = '$forum_posts_real_num' WHERE forum_id = '$forum_id'";
mysql_query($forum_topics_num_update_sql) or die(mysql_error());
6 lines for something so simple seems so much. Is there any syntax I
can change to cut this down?
Re: shortening code
Shorter code isn't always better. If it works I'd leave it, escpecially =
since it seems to be from the phpBB packages, and manually altering file=
could result in a much more troublesome update.
However there is offcourse a simpler way:
mysql_query("UPDATE .phpbb_forums SET forum_posts = forum_post=
+ $num_topics_real WHERE forum_id = $forum_id");
Keep SQL injection in mind...
[SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work =
fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SP=
May 13, 2008, 10:24 am
Re: shortening code
This code seems to put a lot of effort in creating unique names for
variables that do not seem of any use outside this block. I'd say that
replacing stuff like $sql_forum_posts_num and
$forum_topics_num_update_sql with $sql would be a sort of improvement.
Also, some blank lines would make it look less like a brick.
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
- » require_once() question for PHP programmers with C or C++ background
- — Previous thread in » PHP Scripting Forum