Status
Not open for further replies.

immortalxx

Active Member
609
2009
6
0
Does this query look alright?

Code:
                    $this->DB->do_update( 'forums', array( 
                                            'posts=posts+1', 
                                            'last_post' => $now, 
                                            'last_title' => $post_title, 
                                            'last_id' => $topic_id,
                                            'last_poster_id' => $starter_id, 
                                            'last_poster_name' => $starter_name ),
                                            'id='.$forum_id
                     );
 
20 comments
This part is weird... since it´s between single quotes, it refers to a var named posts=posts+1 , weird... but who knows... i´m not IPB lover.

Code:
'posts=posts+1'
Perhaps it should be:

Code:
..... array( 
'posts' => $posts+1 ,
etc....
 
Also, for your query,

Code:
                    $this->DB->do_update( 'forums', array( 
                                            'posts' => 'posts+1', 
                                            'last_post' => $now, 
                                            'last_title' => $post_title, 
                                            'last_id' => $topic_id,
                                            'last_poster_id' => $starter_id, 
                                            'last_poster_name' => $starter_name ),
                                            'id='.$forum_id
                     );

** If you're using IP.Board 3, do_update() is replaced by update().
 
That's odd. Try using the plus: logic operator.

Code:
                    $this->DB->update( 'forums', array( 
                                            'posts' => 'plus:1', 
                                            'last_post' => $now, 
                                            'last_title' => $post_title, 
                                            'last_id' => $topic_id,
                                            'last_poster_id' => $starter_id, 
                                            'last_poster_name' => $starter_name ),
                                            'id='.$forum_id
                     );
 
not sure why that would do anyhting differently it most likely turns the second var into an escaped string so no matter what it is it will become 'plus:1'
 
You need to force the data type to int...

Code:
                    $this->DB->force_data_type['posts'] = 'int';

                    $this->DB->update( 'forums', array( 
                                            'posts' => 'plus:1', 
                                            'last_post' => $now, 
                                            'last_title' => $post_title, 
                                            'last_id' => $topic_id,
                                            'last_poster_id' => $starter_id, 
                                            'last_poster_name' => $starter_name ),
                                            'id='.$forum_id
                     );

Please see the compileUpdateString function in ips_kernel/classDb.php. IPS introduced the logical operators minus: and plus: within update queries with IP.Board 3.
 
Try this:
PHP:
                    $this->DB->update( "forums",  
                                            "posts=posts+1, 
                                            last_post=$now, 
                                            last_title='$post_title', 
                                            last_id=$topic_id,
                                            last_poster_id=$starter_id, 
                                            last_poster_name='$starter_name'" ,
                                            "id=$forum_id"
                     );
 
Try it. I have several that work this way.

Also check this file
Code:
admin\applications\forums\modules_public\extras\vote.php

line 273 of their own system ..
PHP:
			$this->DB->update( 'polls', "votes=votes+1,choices='{$this->topic['choices']}'", "pid={$this->topic['poll_id']}", false, true );
 
Yes, you're correct, but look at the last parameter. By default, it's set to false. Setting it to true means that it's a preformatted 'SET'. I wouldn't manually validate the fields if I don't have to.
 
Do research first? You said it would work when it wouldn't... You simply pasted a dysfunctional code. Don't be upset that I corrected you, dude.
 
My code was correct and I am not upset a some little boy who got spanked by his mommy.
:))

You were wrong "update() expects an array as the second parameter." is absolutely wrong.=):'(

Bet you really are a star in the tenth grade.
 
It does expect an array as a parameter unless you set the last parameter as true, which you do not...

Jesus dude. Let go.
 
Status
Not open for further replies.
Back
Top