Mutlple update

Discussion in 'PHP' started by shadow007, May 12, 2010.

  1. #1
    Is it possible to create a form that can perform multiple updates to a sql database?
     
    shadow007, May 12, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    yah, it can be
     
    gapz101, May 12, 2010 IP
  3. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Yeah Possible depending on the work
     
    roopajyothi, May 12, 2010 IP
  4. shadow007

    shadow007 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Anyone know any examples?

    Thanks
     
    shadow007, May 12, 2010 IP
  5. kvhnuke

    kvhnuke Greenhorn

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    what kind of multiple are you expecting
     
    kvhnuke, May 12, 2010 IP
  6. shadow007

    shadow007 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Basically Im passing a variable over by a form and then showing my table on a page based on that variable.

    So the sql looks something like:

    SELECT *
    FROM CONCERT
    ORDER BY Concert.Seat ASC LIMIT $input_value

    So this page will show the rows based on the variable I have passed over.

    So If i entered 4 and the value of the variable was then 4 I would see 4 seats available (4 rows in the database).

    Now How would I update this into the database using an update form?

    Any help appreciated.
     
    shadow007, May 14, 2010 IP
  7. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #7
    okay, since you have fetched them, you just have to loop through the rows and then update using each unique id ;)
     
    gapz101, May 14, 2010 IP
  8. shadow007

    shadow007 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Erm that sounds hard, how exactly could I do that?
     
    shadow007, May 14, 2010 IP
  9. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #9
    hmm, i'm not google though,,..
     
    gapz101, May 14, 2010 IP
  10. phpSiteMinder

    phpSiteMinder Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Something like that

    UPDATE CONCERT set seat = $somevalue WHERE id = $id

    where somevalue comes from a form.

    Its really hard to give you a solution, since we don't know the fields in the database or how you are using them, but generally, you could print out the id in a form with a checkbox and update the ids in the database where the checkbox is selected.
     
    phpSiteMinder, May 16, 2010 IP
  11. phpSiteMinder

    phpSiteMinder Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Oh, and you'd have to do the update in a loop for each of the ids you got back form the form
     
    phpSiteMinder, May 16, 2010 IP
  12. swashata

    swashata Member

    Messages:
    86
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #12
    Something like this... Hope this helps:
    $dbc = mysqli_connect("localhost", "root", "", "database");
    $query = "SELECT * FROM concert ORDER BY concet.seat ASC LIMIT $input_value";
    $result = mysqli_query($dbc, $query) or die('Error Querying database '.mysqli_error($dbc));
    while($rows = mysqli_fetch_array($result)) {
        $id = $rows['id'];
        $new_query = "UPDATE concet SET concert.seat='$some_value' WHERE id=$id";
        $new_result = mysqli_query($dbc, $new_query) or die('Error Querying database '.mysqli_error($dbc));
        //And you are done now!
        echo "Successfully updated table row with id=$id";
    }
    PHP:
    obviously the variable $some_value has to come from some form or get!
     
    swashata, May 16, 2010 IP
  13. shadow007

    shadow007 Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks alot for your help
     
    shadow007, May 19, 2010 IP