help with PHP mySQL script to convert between PHPnuke and Invision Forum
-
Jchef, I have a PHP script that converts members from a PHPnuke 6.0 website to an Invision Bulletin Board v. 1.2. The problem with the script is that members appear to duplicate every time the script is run, which is often, as a I have a cron job running it every four hours. I know this is a little wasteful, but it is the easiest way (I am not a programmer!) for me to sync membership lists. I would appreciate it if you could help me rewrite the script so that the old members are not duplicated over and over. <?php /************************************/ /* Import phpNuke6.0 users to IPB */ /* By Holbrookau */ /************************************/ require("mainfile.php"); global $dbi, $prefix; $ipbprefix = "ibf"; // Prefix of your IPB tables - edit if required. $nukenum = (sql_num_rows(sql_query("select * from ".$prefix."_users", $dbi))); $sql = "SELECT id FROM $ipbprefix"._members." ORDER BY id DESC LIMIT 1"; $result = sql_query($sql, $dbi); list($id) = sql_fetch_row($result, $dbi); echo "<b>Getting users from phpNuke..</b><br><br>"; $sql = "SELECT uid, uname, email, pass FROM ".$prefix."_users WHERE uid > 2"; $result = sql_query($sql, $dbi); if (!$result) { echo "Error - Could not get members from <b>".$prefix."_users</b> table"; return; } echo "<b>Adding members to IBF..</b><br><br>"; while (list($uid, $uname, $email, $pass) = sql_fetch_row($result, $dbi)) { $result2 = sql_query("INSERT into ".$ipbprefix."_members (id,mgroup, name, password, email) values ('$uid' + ('$id'-2), 3, '$uname', '$pass', '$email')", $dbi); if (!$result2) { echo "Error - Could not add users to <b>".$ipbprefix."_members</b> table"; return; } echo "$uid $uname"; echo "<br>"; } echo "<br><b>".$nukenum." phpNuke users have been successfully added as IPB members.</b><br>Only usernames, email addresses and (encrypted) passwords have been imported. Please check your <b>".$ipbprefix."_members</b> table for duplicate users."; ?>
-
Answer:
Hi, Here you go. I put in a sql check to see if the user name exists before the insert. If the username already exists, it by-passes the instert, otherwise it functions as normal. <?php /************************************/ /* Import phpNuke6.0 users to IPB */ /* By Holbrookau */ /************************************/ require("mainfile.php"); global $dbi, $prefix; $ipbprefix = "ibf"; // Prefix of your IPB tables - edit if required. $nukenum = (sql_num_rows(sql_query("select * from ".$prefix."_users", $dbi))); $sql = "SELECT id FROM $ipbprefix"._members." ORDER BY id DESC LIMIT 1"; $result = sql_query($sql, $dbi); list($id) = sql_fetch_row($result, $dbi); echo "<b>Getting users from phpNuke..</b><br><br>"; $sql = "SELECT uid, uname, email, pass FROM ".$prefix."_users WHERE uid > 2"; $result = sql_query($sql, $dbi); if (!$result) { echo "Error - Could not get members from <b>".$prefix."_users</b> table"; return; } echo "<b>Adding members to IBF..</b><br><br>"; while (list($uid, $uname, $email, $pass) = sql_fetch_row($result, $dbi)) { $check_r = sql_query("select count(*) as countck from " .$ipbprefix."_members where name = '$uname'", $dbi); $a = mysql_fetch_array($check_r); if($a['countck'] <= 0 ) { $result2 = sql_query("INSERT into ".$ipbprefix."_members (id,mgroup, name, password, email) values ('$uid' + ('$id'-2), 3, '$uname', '$pass', '$email')", $dbi); if (!$result2) { echo "Error - Could not add users to <b>".$ipbprefix."_members</b> table"; return; } // end check insert result } // end if check that there are no duplicates // echo "$uid $uname"; echo "<br>"; } // end insert while loop echo "<br><b>".$nukenum." phpNuke users have been successfully added as IPB members.</b><br>Only usernames, email addresses and (encrypted) passwords have been imported. Please check your <b>".$ipbprefix."_members</b> table for duplicate users."; ?> thanks, webadept-ga
alakon2-ga at Google Answers Visit the source
Related Q & A:
- How To Build Business Directory Using Php Mysql?Best solution by Stack Overflow
- How to convert Oracle script to MySQL script?Best solution by Stack Overflow
- How to prevent duplicate entries in MySQL and PHP?Best solution by Stack Overflow
- How to write a query for PHP and MySQL?Best solution by Stack Overflow
- How to start creating a php script, that will be installed on many servers?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.