I am trying to use a mysql query to fill a PHP array but it doesn’t seem to work correctly. Here is the code I am using now:
$a = array();
$rt = mysql_query("SELECT * FROM users WHERE upline='{$ir['username']}' AND uplinetype=2");
while($r=mysql_fetch_array($rt))
{
for($count=0; $count < $ir['referrals']; $count++)
{
$a[$count] = $r['username'];
}
}
foreach($a as $value) {
echo "$value\
";
}
the $ir array is defined elsewhere and I know this isn’t the problem. Am I filling the array wrong or is something wrong with the code? Any help is appreciated. Thanks.
I want to print everything that the mysql query returns and store those values in an array. There should be multiple values where upline="$ir[‘username’] and uplinetype=‘2’.
Okay, one more question. I am not sure if you’re able to do this but: Is there a way I can have a WHERE statement in mysql query where I can compare a table field to the array I just created?
mysql_query("UPDATE users SET upline='{$mainuser['username']}', uplinetype='2',
uplineremains='{$data['uplineremains']}' WHERE username!='{$data['username']}' AND
username!='{$mainuser['username']}' AND upline='' AND
totalclicks>".round($set['refs_minclicks'])." AND lastaction>{$tsp} AND
username!=$aArray LIMIT 1;");
Where $aArray is what I(well, you :D) just created.
This query should do what you ask without using the array we created.
<?php
$sSQL = sprintf("UPDATE users SET upline = '%s', uplinetype = 2, uplineremains = '%s' WHERE username != '%s' AND username != '%s' AND upline = '' AND totalclicks > %s AND lastaction > %s AND username NOT IN (SELECT username FROM users WHERE upline='%s' AND uplinetype = 2) LIMIT 1;",
$mainuser['username'],
$data['uplineremains'],
$data['username'],
$mainuser['username'],
round($set['refs_minclicks']),
$tsp,
mysql_real_escape_string($ir['username'])
);
?>
Well the thing that I am doing is placing new users in a users “upline” field and taking the old ones out. Basically recycling referrals. I don’t want the users recycled to be the same users that were in the downline before. This query is executed 3 times using jquery and I want to make sure that they are not the same referrals. Also, when I used your code…it didn’t work.
It seems like you maybe best of heading on over to the SQL forums, I’m a little lacking in this area and I’m sure any query I put together wouldn’t be the best or most suitable.
Good luck, and I’m sure the guys over there will sort you out.