Log in

View Full Version : vb3 and mysql


TouchingVirus
01-04-2004, 12:27 PM
Hey, i was hopin you would be able to help me with this *half-request*/*half-cry for help*

I have created a table in mysql with 3 fields, (userid, spam, real)

When the user creates a thread in say forumid==2 the post is counted as a Real post..

when the user creats a thread in say forumid==14 the post is counted as a spam post (its in the spam forum ;))

I want to make it so that when the user makes 2 threads in spam forum, that the value of spam increments to two,three, etc...and when they delete a thread, then it decrements..and the same for the "real" value.

I would also like to know how will i distinguish wheter or not the userid is already in the table?

For example i can easily use this statement


if (($foruminfo['forumid']=='7') || ($foruminfo['forumid']=='11') || ($foruminfo['forumid']=='21'))
{
$DB_site->query("INSERT INTO pubscan (userid,spam,real) VALUES('".$bbuserinfo['userid']."',$countspam,$countreal)");
}


But this will throwback an error if the userid is already there...so the alternative is to use the UPDATE function...but how do i check if a userid is already there??

I can run a SQL statement like


SELECT * from spamreal WHERE userid=".$bbuserinfo['userid'].";


but how do i check if it comes back empty?

hwtan
01-05-2004, 05:46 AM
I'm not exactly sure what you want to do, but would it be possible to do this instead?


SELECT userid, count(*) as postcount, forumid FROM post, thread
WHERE post.threadid = thread.threadid GROUP BY userid,forumid;


Alternatively, you can try using REPLACE instead. It works like a DELETE followed by a INSERT.


REPLACE pubscan (userid,spam,real) VALUES($bbuserinfo[userid], $countspam,$countreal);