2012-12-17 2 views
-1

나는 이것에 도움이 필요합니다. 나는 mysql 테이블에 체크 된 항목 만 제출하기를 원한다. 여기php mysql에 체크 된 항목을 삽입하십시오.

는 HTML PHP 페이지에서 렌더링 :

<table id="mylist" data-campaignId="2" cellspacing="0" width="100%"> 
<tbody> 
     <tr> 
     <td><input type="checkbox" name="selected[]" value="92" class="checkbox"></td> 
     <td><a href="/client/view/92">Bob</a></td> 
     <td><ul class="keywords"> 
      <li><a href="#">Peter T</a></li> 
      <li class="orange-keyword"><a href="#">New Lead</a></li> 
     </ul></td> 
     <td>(555) 555-5555</td> 
     <td>[email protected]</td> 
     <td>2011-03-21</td> 
     <td class="table-actions"><a href="/client/view/92" title="View/Edit" class="with-tip"><img src="/images/icons/fugue/pencil.png" width="16" height="16"></a></td> 
    </tr> 
    <tr> 
     <td><input type="checkbox" name="selected[]" value="1074" class="checkbox"></td> 
     <td><a href="/client/view/1074">Elinda Canty</a></td> 
     <td><ul class="keywords"> 
      <li><a href="#">Mary</a></li> 
      <li class="orange-keyword"><a href="#">New Lead</a></li> 
     </ul></td> 
     <td></td> 
     <td>[email protected]</td> 
     <td>2011-06-29</td> 
     <td class="table-actions"><a href="/client/view/1074" title="View/Edit" class="with-tip"><img src="/images/icons/fugue/pencil.png" width="16" height="16"></a></td> 
    </tr> 

</tbody> 
</table> 
<button id="add_users_to_campaign">Add Selected to Subscribers</button> 

여기 페이지의 완전한 소스도 있습니다. 내가 삽입 할

<? $campaignid = $this->uri->segment(4); ?> 
<script type="text/javascript"> 
<!-- 
$(document).ready(function(){ 
toggleChecked = function(status) 
{ 

$(".checkbox").each(function() { 
    $(this).attr("checked",status); 
}); 
} 
}); 
--> 
</script> 

<script type="text/javascript"> 
$(function() { 
$('#add_users_to_campaign').click(function() { 
var campaignId = $("#mylist").attr("data-campaignId"); 
var clientid = []; 
$("#mylist :checked").each(function() { 
    clientid.push($(this).closest("tr").attr("data-clientid")); 
}); 
if (clientid.length === 0) { 
    return; 
} 
console.log(campaignId, clientid); 
$.post('/ajaxmodels/add_users_to_campaign', { 
    campaignId: campaignId, 
    "clientid[]": clientid 
}, function(data) {}, "json"); 
}); 
});​ 
</script> 

<!-- Content --> 
<article class="container_12"> 

<section class="grid_12"> 
    <div class="block-border"> 
    <? 
    $attributes = array('class' => 'block-content form', 'id' => 'table_form'); 
    echo form_open('', $attributes); 
    ?> 
     <h1>Search Fields</h1> 
     <div class="columns"> 
      <p class="colx4-left"> 
       <label>Find</label> 
       <?php echo form_dropdown('quicksearch',$qs_array,'','class="full-width"');?> 
      </p> 
      <p class="colx4-mid"> 
       <label>Where</label> 
       <?php echo form_dropdown('where',$where_array,'','class="full-width"');?> 
      </p> 
      <p class="colx4-center"> 
       <label>Search</label> 
       <?php echo form_input('searchfor','','class="full-width"');?> 
      </p> 
      <p class="colx4-right"> 
       <label>&nbsp;</label> 
       <input type="submit"/> 
      </p> 
     </div> 
    <? echo form_close(); ?></div> 
</section> 

<section class="grid_12"> 
    <div class="block-border"> 
    <form class="block-content form" id="table_form" method="post" action=""> 
     <h1>Sortable table</h1> 

     <table id="mylist" data-campaignId="<?=$campaignid?>" class="table sortable no-margin" cellspacing="0" width="100%"> 

      <thead> 
       <tr> 
        <th class="black-cell"><span class="loading"></span></th> 
        <th scope="col"> 
         <span class="column-sort"> 
          <a href="#" title="Sort up" class="sort-up"></a> 
          <a href="#" title="Sort down" class="sort-down"></a> 
         </span> 
         Name 
        </th> 
        <th scope="col">Client Of</th> 
        <th scope="col"> 
         <span class="column-sort"> 
          <a href="#" title="Sort up" class="sort-up"></a> 
          <a href="#" title="Sort down" class="sort-down"></a> 
         </span> 
         Home Phone 
        </th> 
        <th scope="col"> 
         <span class="column-sort"> 
          <a href="#" title="Sort up" class="sort-up"></a> 
          <a href="#" title="Sort down" class="sort-down"></a> 
         </span> 
         Email 
        </th> 
        <th scope="col"> 
         <span class="column-sort"> 
          <a href="#" title="Sort up" class="sort-up"></a> 
          <a href="#" title="Sort down" class="sort-down"></a> 
         </span> 
         Created On 
        </th> 
        <th scope="col" class="table-actions">Actions</th> 
       </tr> 
      </thead> 

      <tbody> 
      <?php foreach($r->result() as $row) : ?> 
       <tr>" 
        <td> 
        <input type="checkbox" name="selected[]" value="<?=$row->id?>" class="checkbox"> 
        </td> 
        <td><a href="/client/view/<?=$row->id?>"><?=$row->firstname?> <?=$row->lastname?></a></td> 
        <td><ul class="keywords"> 
         <li><a href="#"><?=$row->clientof?></a></li> 
         <li class="orange-keyword"><a href="#"><?=$row->status?></a></li> 
        </ul></td> 
        <td><?=$row->homephone?></td> 
        <td><?=$row->email?></td> 
        <td><?=$row->created?></td> 
        <td class="table-actions"> 
         <a href="/client/view/<?=$row->id?>" title="View/Edit" class="with-tip"><img src="/images/icons/fugue/pencil.png" width="16" height="16"></a> 
        </td> 
       </tr> 
      <?php endforeach;?> 
      </tbody> 

     </table> 

     <div class="clear"></div> 

<div class="block-footer"> 
      <img src="images/icons/fugue/arrow-curve-000-left.png" width="16" height="16" class="picto"> 
      <a href="javascript:toggleChecked('checked')" class="button">Select All</a> 
      <a href="javascript:toggleChecked('')" class="button">Unselect All</a> 
      <span class="sep"></span> 
      <button id="add_users_to_campaign">POST selected</button> 
     </div>     
    </form></div> 
</section> 
</article><!-- End Content --> 

는이 테이블에 항목을 검사 :

ID - 자동 증가

CAMPAIGNID

clientid는

에서 CreationDate

내가 할 수있는 방법이 ?

나는 또한 동일한 campaignid에 clientid를 중복 삽입하는 것을 피할 필요가 있습니다. 따라서이 캠페인 ID에 대한 clientid가 이미 존재하면 삽입을 건너 뜁니다. 여기

내가 현재 컨트롤러 ajaxmodels에있는 기능입니다 :

여기
function add_users_to_campaign(){ 
$campagnid=$this->input->post('campaignid'); 
$client = $this->input->post('client'); 
    foreach ($client as $client_id) { 
     $submit['clientid'] = $clientid; 
     $submit['campaignid'] = $this->input->post('campaignid'); 
     $submit['creationdate'] = date('Y-m-d H:i:s'); 
     $submit['createdby'] = $this->session->userdata('uid'); 
     $newid = $this->campaign_model->add_user_to_campaign($submit); 

    } 
} 

인을 campaign_model-> add_user_to_campaign 내가 항목을 확인하고 페이지가 더으로 새로 고칩니다 제출

function add_user_to_campaign($data) 
{ 
    $this->db->insert('campaign_to_client',$data); 

    $newid = $this->db->insert_id(); 
    return $newid; 
} 

오류가 발생하고 아무것도 삽입되지 않습니다.

+0

어디에서 예를 들어'campaignid','clientid' 및'creationdate'와 같은 정보는 어디에서 왔습니까? – BenM

+0

정보가 PHP 검색 결과 페이지로 나타납니다. creationdate는 삽입 된 현재 날짜 (타임 스탬프)입니다. – DSmith

+0

나는 이것을 시도했지만 도움이 나를 위해 복잡한 내 길을 그래서 내 질문을 단순화했다. http://stackoverflow.com/questions/13897179/post-selected-items-to-table – DSmith

답변

0

첫 번째 인스턴스에서 모두 4 개를 수행하는 대신 (즉, 주위를 둘러보기 위해) 테이블의 한 행만 시도해보고 작동하는지 확인하십시오.

각 항목의 동일한 이름을 사용하지 않는 것도 고려해야합니다. 즉 사용

<input type="checkbox" name="selected[1]" class="checkbox" value="yes"> 
<input type="checkbox" name="selected[92]" class="checkbox" value="yes"> 
<input type="checkbox" name="selected[1024]" class="checkbox" value="yes"> 

EDIT

쌍 다시 형태의 데이터 (즉 이름, 값). 이름은 고유해야합니다. 그러나 당신은 그렇지 않습니다. 값이 selected[]이고 다른 (잠재적 인) 값을 갖는 세 개의 이름이 있습니다. 어떻게 구별합니까?

내 첫 번째 단락은 첫 번째 (디버깅에 대한 이동 간단 더 후 합병증을 추가 할 수 있도록하는 것이 가장 좋습니다 방법을 설명했다.

나는 위에서의 값 비트를 추가 한 멀어져 편집

.

또는이

<input type="checkbox" name="selected[]" class="checkbox" value="1"> 
<input type="checkbox" name="selected[]" class="checkbox" value="92"> 
<input type="checkbox" name="selected[]" class="checkbox" value="1024"> 

MICKEY MOUSE 예를 할 수

PHP 처음

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
</head> 
<body> 
<pre> 

The forms data 
<?php 
$selector = $_GET['selector']; 
print_r($selector); 
echo "Now go through than data\n"; 

foreach ($selector as $name=>$value) 
{ 
    // Find the name 
    $character = $_GET["id$name"]; 

    echo "$character is $name or $value depends on the method you chose\n"; 
} 
echo "\n\nThose are the checked ones"; 
?> 
</pre> 
</body> 
</html> 

그리고 여기 형태 :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Wibble</title> 
</head> 
<body> 
<form action="send.php" method="get"> 
<input type="hidden" name="id0" value="client Joe Bloggs"> 
<input type="hidden" name="id1" value="Client Bugs Bunny"> 
<input type="hidden" name="id2" value="Client Al Capone "> 
Check 1 <input type="checkbox" name="selector[]" value="1"> 
Check 80 <input type="checkbox" name="selector[]" value="80"> 
Check 200 <input type="checkbox" name="selector[]" value="200"> 
<input type="submit" value="depends"> 
</form> 
<form action="send.php" method="get"> 
<input type="hidden" name="id1" value="client Joe Bloggs"> 
<input type="hidden" name="id80" value="Client Bugs Bunny"> 
<input type="hidden" name="id200" value="Client Al Capone "> 
Check 1 <input type="checkbox" name="selector[1]" value="yes"> 
Check 80 <input type="checkbox" name="selector[80]" value="yes"> 
Check 200 <input type="checkbox" name="selector[200]" value="yes"> 
<input type="submit" value="otherway"> 
</form> 

</body> 
</html> 
+0

당신이 무엇을 의미하는지 확실하지 않습니다 ??? – DSmith

+0

위의 EDIT를 참조하십시오. –

+0

Dev - clientid의 속성 값을 추가하고 위에 편집했습니다. 에드 감사하지만 선택은 그것이 어떻게 든 그것이 선택되어 있는지 확인하기위한 것 인 것처럼 선택되어야한다는 것을 읽었습니까 ??? – DSmith

관련 문제