2014-11-23 4 views
0

MY HTMLPHP에서 다중 드롭 다운으로 테이블을 업데이트하려면 어떻게해야합니까?

<div class="normal-text"> 
     <? $check = mysql_query("SELECT * FROM client")or die(mysql_error()); 
      while ($check2 = mysql_fetch_array($check)) 
     { 
      $checkgather = mysql_query("SELECT * FROM gather where client_id = '".$check2['client_id']."' ")or die(mysql_error()); 
      $checkgather2 = mysql_fetch_array($checkgather); 
      echo $check2['client_name'].' : 

       <select name="gather" class=\"form-field\"> 
       <option value="hashtag" '.(($checkgather2['gather_choice']=='hashtag')?'selected="selected"':"").' >hashtag</option> 
       <option value="latitude" '.(($checkgather2['gather_choice']=='latitude')?'selected="selected"':"").' >latitude/longitude</option> 
       <option value="followers" '.(($checkgather2['gather_choice']=='followers')?'selected="selected"':"").'>followers</option> 
       </select> 
      <a href="#" class="link-small">Start Thread to gather</a><br>'; 
     } 
     ?> 
     <br> 
     <input class="submit-button" type="submit" name="submit" value="Update" /> 
    </div> 

나는 .. DB에 무슨 ... 난 하나 개 또는 여러 값을 변경하고, 나는 UPDATE 버튼을 누르면의 드롭 다운 메뉴와 각 ... 어떻게 결과 여러 행이 나는 코드를 처리 할 수 ​​있습니다 ..

내가

현재 PHP이있는 foreach는 (...)를해야 겠지 :

if (isset($_POST['submit'])) 
{ 
    $update = mysql_query("UPDATE gather set gather_choice = ' ' where client_id = ' ' ")or die(mysql_error()); 
} 

하지만 아마거야 foreach를 어딘가에 필요로합니다 ...이 작업을 수행하는 방법에 대한 팁?

감사

답변

0

당신은 당신이 CLIENT_ID

INSERT INTO gather (gather_choice, client_id) 
VALUES (first_choice, first_client_id), (second_choice, second_client_id) 
ON DUPLICATE KEY UPDATE client_id = VALUES(client_id) 

이 기본적으로 첫 삽입을 시도합니다에 고유 키가 가정하지만, 이미 존재하는 것을보고,이 작업을 수행 할 수 있습니다, 그냥 업데이트됩니다.

+0

그리고 (first_choice, first_client_id)를 얻으려면 어떻게해야합니까 .. 배열을 사용해야합니다. .how 여러 개의 gather_choice 및 multiple_client_id가 있으므로 HTML에서 값을 전달하는 방법 ... 내가 숨겨진 클라이언트 ID에 대한 필드 :''배열 없이는 검색 할 수 없습니다. – user3011784

+0

각 입력에는 자체 이름이 필요합니다. client_id [1], client_id [2] 등의 이름을 붙일 것입니다. PHP는 실제로 $ _POST 변수에 배열을 제공합니다. – DAB

+0

죄송합니다. 수집 할 수 있습니다 [. $ client_id.] – DAB

관련 문제