Results 1 to 8 of 8

Thread: Updating multiple fields
      
   

  1. #1
    Phouber is offline Corporal
    Join Date
    May 2008
    Posts
    10

    Default Updating multiple fields

    Hey guys,
    I have a code here that works fine, the problem is i want to update more than 1 field.
    PHP Code:
    function updateField($username$table$field$value) {
     
    con=connect(); //My connection function
     
    $query "UPDATE " .$table" SET " .$field"=" .$value" WHERE username='$username'";
     
    $result mysql_query($query$con) or die(mysql_error());

    Am I allowed to use an array or do I have to use
    PHP Code:
    while($query "UPDATE " .$table" SET " .$field"=" .$value" WHERE username='$username'";) {
     
    mysql_query($query$con);

    Thanks
    Matt

  2. #2
    Phouber is offline Corporal
    Join Date
    May 2008
    Posts
    10

    Default Re: Updating multiple fields

    Hello?

  3. #3
    Phouber is offline Corporal
    Join Date
    May 2008
    Posts
    10

    Default Re: Updating multiple fields

    Hey guys, thanks for the help ;)

  4. #4
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Updating multiple fields

    You got no help because no help can be offered.

    There is no way to batch update a database, at least to my knowledge. You can only create a loop that will repeat the same operation as many times as required.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  5. #5
    Phouber is offline Corporal
    Join Date
    May 2008
    Posts
    10

    Default Re: Updating multiple fields

    a loop such as
    PHP Code:
    while($query "UPDATE " .$table" SET " .$field"=" .$value" WHERE username='$username'";) { 
     
    mysql_query($query$con); 

    ?

  6. #6
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Updating multiple fields

    The loop depends on the logic, but there i can't see the logic in the loop you posted. The loop depends on what you need to to.

    If you can explain the logic, we will be able to help.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  7. #7
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default Re: Updating multiple fields

    All that while loop is checking for is if $query = something... which since you are using a string that stays constant its always going to be assigned at the very least
    "UPDATE SET WHERE username='$username'"

    Now what you need to do is count how many elements are in the array using the count() function. Then just use a for loop (or while loop if you wanted) and go through each element of the array one by one until you have gone through it count() times.

    PHP Code:
    $count count($array);
    for(
    $i=0$i $count$i++)
    {
    // do whatever with... $array[$i]

    Also keep in mind (I don't know if this will work in your exact situation), but you can update more then one column of the same row at a time, just format your query like
    PHP Code:
    UDPATE table_name SET column1='value1'column2='value2'column3='value3' WHERE username='$username' 

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

  8. #8
    Phouber is offline Corporal
    Join Date
    May 2008
    Posts
    10

    Default Re: Updating multiple fields

    Quote Originally Posted by Phouber View Post
    Hey guys, thanks for the help ;)
    Sorry if I offended any1 i was just trying to keep the topic active :D

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49