Friday, 15 January 2010

php - use while with drop down list to update active data on mysql database -


  (my prices have a drop down list with two options), & gt; & Gt; & Lt; Select name = "status" id = "image" & gt; Option value = "0" & ​​gt; & Lt; Option value = "1" & gt; & Lt; / Select & gt; I select tag & gt; & Gt; & Gt; & Gt;  
  • While it is displayed in the code below, these two options are considered

     Activate for position, 0 = is not active, 1 = active, and my column name is activated and email is named column on mysql database, when my problem is selected, select the value = 1, all the rows on the active column For the active column on mysql database update 1, and I have selected all the rows on the active column and Want to update active for the selected value selected I & lt; Php $ qur = mysql_query ("Choose From Sales"); While using the loop in the recovery data from the database (* $ row = mysql_fetch_array ($ qur)) / * with the selection to activate here / and the value of 0 to only the selected value and all {? & Gt; & Lt; TR & gt; & Lt; Td> & Lt; Select name = "status []" id = "status" & gt; & Lt; Option selected & gt; ..... & lt; / Options & gt; & Lt; Option value = "0" & ​​gt; Not active & lt; / Options & gt; & Lt; Option value = "1" & gt; Active & lt; / Options & gt; & Lt; / Select & gt; & Lt; / Td> & Lt; Td align = "center" & gt; & Lt ;? Php echo $ row ['active'] ;? & Gt; & Lt; / Td> & Lt; Td> & Lt ;? Php echo $ line ['email'] ;? & Gt; & Lt; / Td> & Lt; Td> & Lt ;? Php echo $ row ['id'] ;? & Gt; & Lt; / Td> & Lt; / TR & gt; & Lt ;? Php}? & Gt; & Lt; / Table & gt; & Lt; Input type = "submit" name = "chk" value = "get selected value" /> & Lt ;? Php if (isset ($ _ POST ['chk'])) {foreach ($ $ _POST [select $ as 'status']) {echo "you have selected:". Select $; // Selected value displayed at $ sqlr = mysql_query ("Update Sale SET active = '$ select' where id = '". $ Line [' id '].' '' ');}}? & Gt;  

    Return all values ​​when pressing submit 0 or 1 I want to press submit when only the active item and update value on the database

    < / Li>

You have to put a WHERE clause in your query, this is a SQL statement, problem, To say that which line you want Try it, otherwise it will modify all the rows, try it:

  $ sqlr = mysql_query ("UPDATE sales SET active = '". $. "' Id =". $ Line ['id']. ";);  

If the primary key in your table is required to match the field, then assume that the line $ ['id'] That line has a pk value and the $ value is set in the 'active' field.

EDIT: If you actively convert a VARCHAR variable That are used as they should be made a single bid, otherwise do not use single quotes. Are you sure the field ID is PK and the variable $ line ['id'] changes with the actual line id that you want to change?


No comments:

Post a Comment