Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Nov 2001
    Location
    California
    Posts
    1,991

    PHP/mySQL something simple!

    I have a list of names that are comma separated. I need a script that will go and look through a mysql table and find each of these names on separate rows, and edit some information. Can anyone help me out?

  2. #2
    Join Date
    Jan 2005
    Posts
    46
    Assuming you have the data like this:

    $list="name1,name2,name3,name4,name5";

    I think this should work:
    PHP Code:
    $list=explode(',',$list);
    foreach(
    $list as $item){
    $query="UPDATE table SET field='newdata' WHERE name=$item";
    mysql_query($query);

    Pretty crude, but it should suffice.

  3. #3
    Join Date
    Nov 2001
    Location
    California
    Posts
    1,991
    It's not working for some reason.

  4. #4
    Join Date
    Nov 2001
    Location
    California
    Posts
    1,991
    Anyone else?

  5. #5
    Join Date
    Jun 2003
    Location
    California
    Posts
    51
    Are you getting any type of error and have you put in any code that connects to your database prior to intransits code?

  6. #6
    The only problem I see is that there should be quotes around $item in the query. What code are you using exactly?

  7. #7
    Join Date
    Nov 2001
    Location
    California
    Posts
    1,991
    I got it, thanks a lot guys!
    Last edited by iamdave; 05-10-2005 at 03:59 AM.

  8. #8
    Join Date
    Nov 2001
    Location
    California
    Posts
    1,991
    One thing, how can I do it so that it checks for new line instead of a comma? And also how do I count how many were actually edited?

  9. #9
    Join Date
    Sep 2002
    Location
    US
    Posts
    133
    $list=explode('\n',$list);
    $i = 0;
    foreach($list as $item){
    $query="UPDATE table SET field='newdata' WHERE name=$item";
    $i++;
    mysql_query($query);
    }
    echo ("$i times");

  10. #10
    Join Date
    Nov 2001
    Location
    California
    Posts
    1,991
    I already tried \n, it only works on the first one.

  11. #11
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,104
    If this list is coming from a file, you can just do $list = file("somefile.txt") -- otherwise you need $list = explode("\n",$list);

    "\n" not '\n'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •