let me see if I understand. In your previously suggested code, the
mysql_fetch_assoc() function is supposed to retrieve ALL the matching userid's, right?
and then the implode() function is supposed to lump them all together into a single variable ($ary) which, if I view it should look something like
21,45,71,101,131,137,168,229,343,375,380,386,429,439,467,576,618,664,822,830,858,919,920
then the
`userid` IN (".$ary.")" clause of the UPDATE command would find any userid that matches anything in the "imploded" field.
Makes sense to me, so why didn't it work? my
echo $ary, "<br>"; command should have caused something resembling
21,45,71,101,131,137,168,229,343,375,380,386,429,439,467,576,618,664,822,830,858,919,920 to appear on the screen, but only "21" appeared.
I actually
have gotten it to work, though it's probably terribly clumsy (certainly not as elegant as your "foreach" function). My apparently functional hack job is as follows:
echo "selecting userids for 68104<br>";
$sql = 'SELECT userid FROM `phplist_user_user_attribute` WHERE `attributeid`= 7 AND `value` LIKE "99999"';
echo "querying for selected userids<br>";
$query = mysql_query($sql);
echo "setting attribute<br>";
echo $rows = mysql_num_rows($query), " rows selected<br>";
$i = 0;
while ($i < $rows) {
$i = $i+1;
if (mysql_num_rows($query)) {
$ary = implode(',', mysql_fetch_assoc($query));
echo $i, " userid: ", $ary, "<br>";
$update = "UPDATE `phplist_user_user_attribute` SET `value` = 'on' WHERE `attributeid` ='16' AND `userid` IN (".$ary.")";
mysql_query($update);
}}
echo "done<br>";
yields the following display:
selecting userids for 68104
querying for selected userids
setting attribute
23 rows selected
1 userid: 21
2 userid: 45
3 userid: 71
4 userid: 101
5 userid: 131
6 userid: 137
7 userid: 168
8 userid: 229
9 userid: 343
10 userid: 375
11 userid: 380
12 userid: 386
13 userid: 429
14 userid: 439
15 userid: 467
16 userid: 576
17 userid: 618
18 userid: 664
19 userid: 822
20 userid: 830
21 userid: 858
22 userid: 919
23 userid: 920
done
and appears to be setting the "targeted" field as desired. What d'ya think?
~kyle