updating more than one record in MySQl using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gnawz
    New Member
    • Nov 2006
    • 64

    updating more than one record in MySQl using PHP

    Dear PHP experts,

    I have a small problem.

    I need help oh how I can be able to update more than on record and save it all in one click.

    I need to read data from a database, say of 200 different items.
    I would like to edit the price of each item but I do not want it done 1 by one.

    I want to be able to display all items or a fragment of them (paginated. say 20 par page) each with its price in an text box, edit the price, then click save and all the item prices I have edited are saved. Same way phpmyadmin can allow one to check fields to edit, then open them in an editable display, edit them and click save or the way one can edit comments of photos in social networking utilities, then save all in one button click.

    I will appreciate any help
    Last edited by Markus; Apr 22 '09, 10:20 PM. Reason: 'freaks' is not a nice thing to call people.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by gnawz
    Dear PHP experts,

    I have a small problem.

    I need help oh how I can be able to update more than on record and save it all in one click.

    I need to read data from a database, say of 200 different items.
    I would like to edit the price of each item but I do not want it done 1 by one.

    I want to be able to display all items or a fragment of them (paginated. say 20 par page) each with its price in an text box, edit the price, then click save and all the item prices I have edited are saved. Same way phpmyadmin can allow one to check fields to edit, then open them in an editable display, edit them and click save or the way one can edit comments of photos in social networking utilities, then save all in one button click.

    I will appreciate any help
    Originally posted by http://php.net/mysql_query
    mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .
    You'll most likely have to loop through the queries.

    Although, this looks interesting.

    Comment

    • gnawz
      New Member
      • Nov 2006
      • 64

      #3
      I need to be able to do something like what phpmydamin does to edit fields

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Originally posted by gnawz
        Dear PHP experts,

        I have a small problem.

        I need help oh how I can be able to update more than on record and save it all in one click.

        I need to read data from a database, say of 200 different items.
        I would like to edit the price of each item but I do not want it done 1 by one.

        I want to be able to display all items or a fragment of them (paginated. say 20 par page) each with its price in an text box, edit the price, then click save and all the item prices I have edited are saved. Same way phpmyadmin can allow one to check fields to edit, then open them in an editable display, edit them and click save or the way one can edit comments of photos in social networking utilities, then save all in one button click.

        I will appreciate any help
        You need loops. In html if you name fields with square brackets [] at the end of them, fields of the same name will be put into an array by PHP's global var $_POST[]

        You will need two fields at least in this type. The unique ID of each record (hidden field or not) and of course the price text box.

        Once you've updated each record, PHP can loop through all the ID and execute a query for each one. (Something like: "UPDATE myTable SET price = " . $price[$] . " WHERE id = " . $id[$i])

        Voila!

        This is of course the basic idea, you would have to know some level of programming to successfully AND SECURELY implement this solution.

        Good Luck,



        Dan

        Comment

        Working...