Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2005
    Posts
    15

    Question Unanswered: MySQL Update Advice

    I am trying to design a simple inventory tracking page with MySQL. Here is how far I am: http://www.localheroclothing.com/viewall.php. My problem deals with updating the quantity. I'm pretty new to MySQL, and I'm looking for a little advice/help on how to go about doing this.

    My idea is that each quantity is in a text input where I can either change the number or click the button next to the box (JS). The buttons are not hooked to the box yet because I haven't figured out how to make each field name unique or if that would mess up the MySQL stuff. I don't want to have to submit after every change, I want to be able to make all the changes and submit them all at once.

    Finally my specific questions: I have read a little about the UPDATE command, but I'm not sure how to use it in my situation where many things need updated. How would I go about displaying each DB table row and have the ability to update it?
    (If it matters) I also need to make each field name unique to use my JS "+" and "-" buttons.

    I appreciate any suggestions about how to tackle this. Here is the stipped-down code of the page:
    PHP Code:
    <? 
    #connect to inventory database and Products table works 
    $sql="select product, productsize, productcolor, productquantity from Products order by product, productcolor"

    $rs mysql_query$sql$conn ); 
    echo(
    "<form action\"" $self "\" method=\"post\"><table>"); 
    while( 
    $row =mysql_fetch_array($rs) ) 

    echo(
    "<tr><td>" $row["product"] . "</td>" ); 
    echo(
    "<td>" $row["productcolor"] ."</td><td>" $row["productsize"] ."</td><td><input type=\"text\" value=\"" $row["productquantity"] . "\"><input type=\"button\" value=\" + \" onclick=\"document.form1.textfield.value=document.form1.textfield.value-(-1);\"> 
    <input type=\"button\" value=\" - \" onclick=\"document.form1.textfield.value=document.form1.textfield.value-1;\"></td></tr><br>"
    ); 


    echo(
    "</table><br><input type=\"submit\" value=\"Submit\"></form>"); 
    ?>

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    If you want to update multiple rows with unrelated data (ie. all new quantity counts in a shopping cart), you will need to use an UPDATE for each affected row.

Posting Permissions

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