Auto update nsngr group table. Help please..

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   Auto update nsngr group table. Help please..
shrek_rock
CZ Newbie
shrek_rock has been a member for over 20 year's 20 Year Member
Status: Offline
Joined: May 30, 2004
0.00 posts per day
Posts: 8
Points: 1,219
   
Hi, here is the problem I am having. I have the bbgroups table that has groupname, description and id. What i would like to do is have a page that when people visit a couple queries will execute updating the nsngr groups table with those info. So i would like it to take information from the bbgroups table and update the nsngr groups table. It would be great if it could check first if those group exist and if not it would then create the new group but if it already exist it would then update the member count if there are new members in that group. Hope you can help,,

Thanks...

Here are some bits of codes i am working with..this code adds groups and users but it also duplicates it every time someone visits the page...I would like it to update instead..



$change3 = $db->sql_query("SELECT group_id, group_name, group_description FROM ".$prefix."_bbgroups WHERE group_single_user=0");
while(list($phpBB, $gname, $gdesc) = $db->sql_fetchrow($change3)) {
$result = $db->sql_query("INSERT INTO ".$prefix."_nsngr_groups VALUES (NULL, '$gname', '$gdesc', '0', '0', '$phpBB', '0')");
if (!$result) { echo "- Insert into ".$prefix."_nsngr_groups failed<br>\n"; } else { echo "- Insert into ".$prefix."_nsngr_groups succeeded<br>\n"; }
list($gid) = $db->sql_fetchrow($db->sql_query("SELECT gid FROM ".$prefix."_nsngr_groups WHERE phpBB='$phpBB'"));
$change4 = $db->sql_query("SELECT user_id FROM ".$prefix."_bbuser_group WHERE group_id='$phpBB'");
while(list($guid) = $db->sql_fetchrow($change4)) {
list($guname) = $db->sql_fetchrow($db->sql_query("SELECT username FROM ".$user_prefix."_users WHERE user_id='$guid'"));
$result = $db->sql_query("INSERT INTO ".$prefix."_nsngr_users VALUES ('$gid', '$guid', '$guname', '0', '0', now(), '0')");
if (!$result) { echo "- Insert into ".$prefix."_nsngr_users failed<br>\n"; } else { echo "- Insert into ".$prefix."_nsngr_users succeeded<br>\n"; }
}
}
$change1 = $db->sql_query("SELECT group_id, group_moderator FROM ".$prefix."_bbgroups WHERE group_moderator>0");
while(list($pgid, $muid) = $db->sql_fetchrow($change1)) {
$result = $db->sql_query("UPDATE ".$prefix."_nsngr_groups SET muid='$muid' WHERE phpBB='$pgid'");
if (!$result) { echo "- Update ".$prefix."_nsngr_groups failed<br>\n"; } else { echo "- Update ".$prefix."_nsngr_groups succeeded<br>\n"; }
list($gid) = $db->sql_fetchrow($db->sql_query("SELECT gid FROM ".$prefix."_nsngr_groups WHERE phpBB='$pgid'"));
$nnum = $db->sql_numrows($db->sql_query("SELECT uid FROM ".$prefix."_nsngr_users WHERE gid='$gid' AND uid='$muid'"));
$bnum = $db->sql_numrows($db->sql_query("SELECT user_id FROM ".$prefix."_bbgroups WHERE group_id='$pgid' AND user_id='$muid'"));
if(!$nnum || $nnum == 0) {
list($guname) = $db->sql_fetchrow($db->sql_query("SELECT username FROM ".$user_prefix."_users WHERE user_id='$muid'"));
$sdate = time();
$result = $db->sql_query("INSERT INTO ".$prefix."_nsngr_users VALUES ('$gid', '$muid', '$guname', '0', '0', $sdate, '0')");
if (!$result) { echo "- Insert into ".$prefix."_nsngr_users failed<br>\n"; } else { echo "- Insert into ".$prefix."_nsngr_users succeeded<br>\n"; }
}
if(!$bnum || $bnum == 0) {
$result = $db->sql_query("INSERT INTO ".$prefix."_bbuser_group VALUES ('$pgid', '$muid', '0')");
if (!$result) { echo "- Insert into ".$prefix."_bbuser_group failed<br>\n"; } else { echo "- Insert into ".$prefix."_bbuser_group succeeded<br>\n"; }
}
}



Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   
Use the same method you use to check these:


$bnum = $db->sql_numrows($db->sql_query("SELECT user_id FROM ".$prefix."_bbgroups WHERE group_id='$pgid' AND user_id='$muid'"));
if(!$nnum || $nnum == 0) {




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: Auto update nsngr group table. Help please..
shrek_rock
CZ Newbie
shrek_rock has been a member for over 20 year's 20 Year Member
Status: Offline
Joined: May 30, 2004
0.00 posts per day
Posts: 8
Points: 1,219
   
Thanks for your prompt reply icon_smile.gif. I have decided to use the code below because it would just about do what i want except for one thing. How would I display only new records from the _bbgroups table. I would like it to compare group id from _bbforums and phpBB data from nsngr_groups. Here is the query..



$bnum = $db->sql_query("SELECT group_id, group_name, group_description FROM ".$prefix."_bbgroups WHERE group_single_user=0 ");
while(list($phpBB, $gname, $gdesc) = $db->sql_fetchrow($bnum)) {

$result = $db->sql_query("INSERT INTO ".$prefix."_nsngr_groups VALUES ('0', '$gname', '$gdesc', '0', '0', '$phpBB', '0')");
}



That code inserts the data and created duplicates. Could i list only data from the _bbforums that are not inside the nsngr_forums table then use the insert at the bottom to add those data..Maybe something like the following..


$bnum = $db->sql_query("SELECT group_id, group_name, group_description FROM ".$prefix."_bbgroups WHERE group_id !=='phpBB' ");


I tried that and it didn't work so anything like that would be great..Thanks again icon_smile.gif...



Back to top Reply with quote
#4   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   
Your trying to see if something already exists?


WHERE group_id !='phpBB' ");


Only need one = sign.

I would try to query for that exact information then if there is no result execute the second query. Let me know if you need help with that.



_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum