Announcement

Collapse
No announcement yet.

Updating multiple fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Re: Updating multiple fields

    Hello?

    Comment


    • #3
      Re: Updating multiple fields

      Hey guys, thanks for the help ;)

      Comment


      • #4
        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!

        Comment


        • #5
          Re: Updating multiple fields

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

          ?

          Comment


          • #6
            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!

            Comment


            • #7
              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

              Comment


              • #8
                Re: Updating multiple fields

                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

                Comment

                Working...
                X