User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 373,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,013 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:

help a newbie? mySQL find & replace

Join Date: Aug 2006
Posts: 15
Reputation: kyleknapp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kyleknapp kyleknapp is offline Offline
Newbie Poster

Re: help a newbie? mySQL find & replace

  #12  
Oct 12th, 2006
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
Reply With Quote  
All times are GMT -4. The time now is 6:23 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC