Log in

View Full Version : Product Install Code - Adding a row for each row in user


Nullifi3d
02-07-2006, 03:40 PM
Upon product install I need to add a row to a mysql table for each row that is in the table 'user'. How would I do this bring the userid and username intot he new table? I think it's something like this: $vbuser =& $vbulletin->userinfo;
foreach ($vbuser AS $userid => $userid, $username => $username,) {
$db->query_write("INSERT INTO " . TABLE_PREFIX . "banners (
userid, username, title, url, link, ext, width, height, clicks, available, impressions, status
) VALUES (
'$userid', '$username', '', '', '', '', '', '', 0, '{$vbulletin->options['banner_impressions_join']}', 0, ''
)");
}I know that $vbulletin->userinfo contains info for the user visiting the page, so it would not work. What do I need to do to make this work?

Andreas
02-07-2006, 03:51 PM
Untested, but should work (if I havn't added a typo or smth.)


$db->query_write("
INSERT INTO " . TABLE_PREFIX . "banners
(userid, username, title, url, link, ext, width, height, clicks, available, impressions, status)
(SELECT user.userid, user.username, '' AS title, '' AS url, '' AS link, '' AS ext, 0 As width, 0 AS height, 0 AS clicks, 0 AS available, 0 AS status)
FROM " . TABLE_PREFIX . "user AS user)
");

Nullifi3d
02-07-2006, 03:58 PM
Ahh, suprised I didn't think of that for the query, but will that add a row every user in the table 'user' when the product is installed? What if there is 300 users in the table? it looks like this will only add 1 row.

Andreas
02-07-2006, 04:05 PM
It should add rows for all users.

Nullifi3d
02-07-2006, 04:10 PM
Thank you it did work.