2017-09-14 1 views
0

내가 PHP에서 초보자 해요, 이것은이 내 데이터가 코드를 생성 내 코드어떻게 데이터베이스에 동적 값을 얻을 수

<h3 class="green">Generate Report</h3> 
    <p>Please select the date range of the report you wish to print.</p> 
    <form id="generate-pdf" action="print.php" method="post"> 
<table class="activate-res"> 

    <tr> 
     <td><p class="form-type-left">Course Activity:</p> 
      <select id="" name="courseActivity" class="dropdown" > 
       <option value="">--Unspecified--</option> 
       <option value="all">All time</option> 
       <option value="7">Last 7 days</option> 
       <option value="30">Last 30 days</option> 
      </select> 
     </td> 
    </tr> 

</table> 



<?php if (isset($_SESSION["site_admin"]) && (int) $_SESSION["site_admin"]) { ?> 

     <h3 class="green">Select site(s)</h3> 
     <p>Please select which sites to include in the report.</p> 

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){ 
$('#select-all').on('change', function() { 
    $('.listSite input[type="checkbox"]').prop('checked', this.checked); 
}); 
$('.listSite input[type="checkbox"]').on('change', function() { 
    var allChecked = $('.listSite input:checked').length === $('.listSite input').length; 
    $('#select-all').prop('checked', allChecked); 
}); 
});//]]> 

</script> 

<table class="err_highlight activate-res" style="border:1px solid #fff"> 
    <tr> 
     <td><input type="checkbox" value="All Sites" id="select-all" name="selectSite"></td> 
     <td>All Sites</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Chilterns"></td> 
     <td>Chilterns</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Fakenham"></td> 
     <td>Fakenham</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Grimsby"></td>  
     <td>Grimsby</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Head Office"></td>  
     <td>Head Office</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Headcorn"></td> 
     <td>Headcorn</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Histon"></td> 
     <td>Histon</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Killingbeck"></td>  
     <td>Killingbeck</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Luton"></td> 
     <td>Luton</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Waterside Park"></td> 
     <td>Waterside Park</td> 
    </tr> 
    <tr> 
     <td class="listSite"><input name="selectSite" type="checkbox" value="Westwood"></td> 
     <td>Westwood</td> 
    </tr> 
</table> 

<?php } ?> 

<!-- onClick="document.location.href='template.php'" --> 
<table class="activate-res"> 
<tr> 
    <td><input name="submit" type="submit" value="Generate Report" class="log-button" /></td> 
     <td><input name="cancel" type="button" value="Cancel" class="log-button" onClick="document.location.href='admin-serials.php'" /></td> 
</tr> 
</table> 
</form> 

</div><!-- content --> 
</div><!-- wrapper --> 

<?php include('footer.php') ?> 

입니다하지만 난 동적 출력하고자이 정적 방법을 변경할 수 수 b ? 내가 모든 것을 선택하면 데이터베이스에서 모든 사이트 데이터를 가져와 표시합니다. 또는 7 일 또는 30 일을 선택하면 7 일 또는 30 일 데이터를 표시하고 다음 10 개의 사이트가 정적으로 표시되지만 동적 인 경우에도 변경됩니다 확인란을 모두 선택하거나 선택한 것을 선택한 다음 데이터를 생성하려면 클릭하십시오. 그것은 Westwood를 선택한 다음 Westwood를 데이터로 가져 오거나 모든 데이터를 표시하도록 선택하는 것을 의미합니다.

+0

은이 같은 전자 메일을 작성하려면 어떻게해야합니까? – DontVoteMeDown

+0

아니오 ....... 해당 데이터 테이블 ..... 보고서 –

답변

0

요청 변수를 가져 와서 각 루프마다 mysql where 절을 넣고 결과를 루프에 표시해야합니다. 예를 들어

:

$where = ''; 
foreach ($requests as $req) 
{ 
    $where .= ' where {$column_name} = {$req}'; 
} 

$result = 'select * from table ' . $where; 

//and loop in HTML 

foreach ($result as $item) 
{ 
echo $item. '<br />'; 
} 

감사 아딜

+0

아무도이 문제를 해결할 수 있습니다. –

+0

위의 예제는 정확한 문제는 무엇인지 문제를 해결하지 못합니까? –

+0

안녕하세요 @ 아딜 ......... 메신저하지만 메신저 나 잘못 넣어 ........ 미안하지만 내 위의 코 드에 넣어 귀하의 예를 들어주십시오 그리고 나를 보내 ... 가능하다면 –

관련 문제