Topic: Multiple SQL Updates

Not really sure where to put his Q since it's a php-coding, sql-update Q from the category/forums section in the admin-area from pub smile

How have you solved the Update All-stuff when you update all forums/categories for among other things position etc?

Do you make one update/forum, or a multi-update directly (if it's possible)?

Re: Multiple SQL Updates

Well, if you have a look at the source code, you can see that I run one SQL UPDATE for every forum. It's the only way of doing it.

Try adding dump($_POST); after the confirm_referer() row and then click "Update All". It will display the contents of POST and then I think you will see how it's done.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Multiple SQL Updates

Ahh, i c, you just loop through the arrays...
In the following line: $forums_to_process = (isset($_POST['update'])) ? array_keys($_POST['update']) : array_keys($_POST['forum_name']);

What does the '?' and ':' do/mean?

Re: Multiple SQL Updates

It's the so called "ternary operator".

print ($a > 5) ? 'yes' : 'no';

is the same as

if ($a > 5)
    print 'yes';
else
    print 'no';

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Multiple SQL Updates

Ahh, yeah i see how that can be usable.
Is it speed/security/failsafewise as stable/good as an ordenary if-else-ladder?

Re: Multiple SQL Updates

Yes. I also like the fact that is forces you to have an "else" block.

$is_admin = (is_admin($user)) ? true : false;

If it were a regular if, one could do:

if (is_admin($user))
    $is_admin = true;

And "forget" about the false. Then someone forgets to turn off register_globals and anyone can do script.php?is_admin=1 and voila! A security hole :)

Edit: Ok, the above is a bad example since one would only have is_admin() return true or false, but you get the idea :)

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Multiple SQL Updates

Yeah, altho i only use $_ vars and require ppl to run updated software smile, i always terminate my if-else/switch-case with a default-block "Error contact admin" or something.

I think it's good code-practice to do so.