Badge SQL Query

Nevada

Member
Oct 16, 2011
63
3
Hello,
I have a list of user ID's (about 500) which I need to send the same badge to. Would someone be able generate my a query which I can put the ID's into so the badge gets sent to all of them without me having to do it manually?
Thanks!
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
PHP:
<?php
mysql_query( "UPDATE `Users` SET `Badge` = 'badge_string'" );
?>

That would set their badge to 'badge_string' to every user.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
You have the ID's?
Well, put them in an array like this:

PHP:
<?php
$user_ids = array( 1, 2, 3 ); //a list of the users you want to send the badge to
foreach ( $user_ids as $id )
{
    mysql_query( "UPDATE `Users` SET `Badge` = 'badgecode' WHERE `UserID` = '" . $id . "'" );
}
?>

I'll let you do the Phoenix db shit, I don't know how the database is structured so you'll have to replace '`Users`', '`Badge`' and '`UserID`' with whatever Phoenix uses.
 

Nevada

Member
Oct 16, 2011
63
3
You have the ID's?
Well, put them in an array like this:

PHP:
<?php
$user_ids = array( 1, 2, 3 ); //a list of the users you want to send the badge to
foreach ( $user_ids as $id )
{
    mysql_query( "UPDATE `Users` SET `Badge` = 'badgecode' WHERE `UserID` = '" . $id . "'" );
}
?>

I'll let you do the Phoenix db shit, I don't know how the database is structured so you'll have to replace '`Users`', '`Badge`' and '`UserID`' with whatever Phoenix uses.
There is a separate table for badges called 'user_badges' the table has 2 collumns one for User ID called 'user_id' and one for badge ID 'badge_id'
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Try something like

PHP:
<?php
$user_ids = array( 1, 2, 3 ); //a list of the users you want to send the badge to
foreach ( $user_ids as $id )
{
    mysql_query( "UPDATE `user_badges` SET `badge_id` = 'badgecode' WHERE `user_id` = '" . $id . "'" );
}
?>

Or something, I'm not entirely sure.
 

Nevada

Member
Oct 16, 2011
63
3
Try something like

PHP:
<?php
$user_ids = array( 1, 2, 3 ); //a list of the users you want to send the badge to
foreach ( $user_ids as $id )
{
    mysql_query( "UPDATE `user_badges` SET `badge_id` = 'badgecode' WHERE `user_id` = '" . $id . "'" );
}
?>

Or something, I'm not entirely sure.
I'm getting:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php
$user_ids = array( 1, 2, 3 )' at line 1


I'm using Navicat
 

brsy

nah mang
May 12, 2011
1,530
272
That would work, but he would then have to type in all the numbers, way up to 500? Why couldn't he do something like this:
PHP:
<?php
$badecode = ""; // Put the badge ID here

    mysql_query( "UPDATE `user_badges` SET `badge_id` = '" . $badgecode . "' WHERE `user_id` = '" . $id <= 500 . "'" );
?>
Put that in a file called setBadge.php, and put it onto your server. Once it's on your server, go to it, then you're good to go.
 

Nevada

Member
Oct 16, 2011
63
3
The thing is, the ID's are 500 random ID's like:
Code:
85108, 89329, 48628, 99474, 2325, 87283, 25997, 76514, 95880, 88795, 43490, 93312, 96788, 42730, 6532, 37167, 644, 101400, 80333, 32841, 15009, 26240, 65647, 19145, 52557, 101100, 10194, 66330, 98767, 99041, 3315, 101515, 25630, 99474, 55312, 84066, 96669, 17610, 4907, 71694, 16443, 51782, 28931, 82211, 34125, 101510, 69990
etc.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
PHP:
<?php
$users = "85108, 89329, 48628, 99474, 2325, 87283, 25997, 76514, 95880, 88795, 43490, 93312, 96788, 42730, 6532, 37167, 644, 101400, 80333, 32841, 15009, 26240, 65647, 19145, 52557, 101100, 10194, 66330, 98767, 99041, 3315, 101515, 25630, 99474, 55312, 84066, 96669, 17610, 4907, 71694, 16443, 51782, 28931, 82211, 34125, 101510, 69990";
$usersexp = explode( ", ", $users );
foreach ( $usersexp as $id )
{
    mysql_query( "UPDATE `user_badges` SET `badge_id` = 'badgecode' WHERE `user_id` = '" . $id . "'" );
}
?>

Try that.
 

Nevada

Member
Oct 16, 2011
63
3
PHP:
<?php
$users = "85108, 89329, 48628, 99474, 2325, 87283, 25997, 76514, 95880, 88795, 43490, 93312, 96788, 42730, 6532, 37167, 644, 101400, 80333, 32841, 15009, 26240, 65647, 19145, 52557, 101100, 10194, 66330, 98767, 99041, 3315, 101515, 25630, 99474, 55312, 84066, 96669, 17610, 4907, 71694, 16443, 51782, 28931, 82211, 34125, 101510, 69990";
$usersexp = explode( ", ", $users );
foreach ( $usersexp as $id )
{
    mysql_query( "UPDATE `user_badges` SET `badge_id` = 'badgecode' WHERE `user_id` = '" . $id . "'" );
}
?>

Try that.
Ok so what do I do with this, run it as a query or put it as a .php file and go to it?
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Put it in a PHP file, but make sure your database connection is established in there, or it will throw you a list of MySQL errors all saying more-or-less the same thing.
 

Users who are viewing this thread

Top