#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    From reading past posts I 'think' this should work but it isn't. Help please.

    I am trying to update the column 'ourpage' in all rows of the database busdir2 where cat=farming. It reads only rows where cat=farming correctly but isn't getting the ourpage value into the table.

    ****************
    $result = mysql_query("SELECT * FROM busdir2 WHERE cat='FARMING' ORDER by state, city, who ASC",$db);
    if ($myrow = mysql_fetch_array($result))
    {
    do {
    printf("%s , %s , %s<BR><BR><BR>n", $myrow["cat"], $myrow["ourpage"], $myrow["id"]);

    {
    "UPDATE busdir2 SET ourpage = 'newvalue' WHERE id=$id";

    }


    } while ($myrow = mysql_fetch_array($result));
    }
    else
    {
    echo "Sorry, no records were found!";
    }

    *************************
    The printf() was inserted to check which rows were being picked out. Should it be removed for the update to work?

    Grasping at straws,

    stujohnson
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,640
    Rep Power
    4476
    Is this your actual code? You're update shoudl be within mysql_query().

    Also, I think you can do this update with just one sql statement.

    $result = mysql_query("UPDATE busdir2 SET ourpage='newvalue' WHERE cat='FARMING'");

    Isn't that what you're shooting for?

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    Thanks John.

    The above did the trick.

    stujo

Similar Threads

  1. Replies: 18
    Last Post: May 6th, 2004, 01:23 PM
  2. Limiting factor of update/insert performance
    By bcyde in forum PostgreSQL Help
    Replies: 12
    Last Post: February 26th, 2004, 02:14 PM
  3. insert and update 2 tables
    By welly in forum PHP Development
    Replies: 14
    Last Post: February 23rd, 2004, 07:41 AM
  4. sql update inserts '0' and not var
    By SeenGee in forum PHP Development
    Replies: 2
    Last Post: February 16th, 2004, 09:18 PM
  5. update data in database
    By Phuspha in forum MySQL Help
    Replies: 2
    Last Post: November 7th, 2003, 01:09 AM

IMN logo majestic logo threadwatch logo seochat tools logo