2014-04-02 140 views
0

我希望此選擇過濾器只有在語言計數超過4時纔會顯示。 任何想法?PHP,HTML過濾器

這裏是HTML選擇過濾器代碼:

<p> 
Select date: 
</p> 
<form method="get" action=""> 
<select id="training_session" name="date"onchange=this.form.submit()> 
<option value=""<?php if($_GET['date'] === '') echo 'selected' ?>>[All dates]</option> 
<option value="April"<?php if($_GET['date'] === 'April') echo 'selected' ?>>April</option> 
<option value="May"<?php if($_GET['date'] === 'May') echo 'selected' ?>>May</option> 
<option value="June"<?php if($_GET['date'] === 'June') echo 'selected' ?>>June</option> 
<option value="July"<?php if($_GET['date'] === 'July') echo 'selected' ?>>July</option> 
<option value="August"<?php if($_GET['date'] === 'August') echo 'selected' ?>>August</option> 
<option value="September"<?php if($_GET['date'] === 'September') echo 'selected' ?>>September</option> 
<option value="October"<?php if($_GET['date'] === 'October') echo 'selected' ?>>October</option> 
<option value="November"<?php if($_GET['date'] === 'November') echo 'selected' ?>>November</option> 
</form> 
<noscript><input type="hidden" value="filter"></noscript> 

這裏是PHP代碼:

if (isset($_GET['date']) && $_GET['date']) { 
    foreach ($training_sessions as $key => $session) { 
     if (date('F', strtotime($session['ZCS_b_date'])) !== $_GET['date']) { 
      unset($training_sessions[$key]); 

讓我怎麼讓它顯示出來只有語言數超過4我有語言選擇過濾器必須一直呆在那裏,但我希望日期過濾器只在語言數超過4時才顯示。

這是語言選擇過濾器代碼:

<p> 
Select language: 
</p> 

<form method="get" action=""> 
<select id="training_session" name="lang" onchange=this.form.submit()> 
<option value=""<?php if($_GET['lang'] === '') echo 'selected' ?>>[All languages]</option> 
<option value="English" <?php if($_GET['lang'] === 'English') echo 'selected' ?>>English</option> 
<option value="Portuguese"<?php if($_GET['lang'] === 'Portuguese') echo 'selected' ?>>Portuguese</option> 
<option value="French"<?php if($_GET['lang'] === 'French') echo 'selected' ?>>French</option> 
<option value="Italian"<?php if($_GET['lang'] === 'Italian') echo 'selected' ?>>Italian</option> 
<option value="Japanese"<?php if($_GET['lang'] === 'Japanese') echo 'selected' ?>>Japanese</option> 
</form> 
<noscript><input type="hidden" value="filter"></noscript> 

這是語言選擇濾波器的PHP代碼:

if (isset($_GET['lang']) && $_GET['lang']) { 
    foreach ($training_sessions as $key => $session) { 
     if ($session['training_language'] !== $_GET['lang']) { 
      unset($training_sessions[$key]); 

因此,沒有人知道什麼IM試圖在這裏實現?我想做的事。

+0

沒人能幫助我嗎? ( – user3480148

+0

)我應該如何使用PHP如果計數?我應該怎麼做? – user3480148

回答

0

確定這裏,我們去..
如果你想這應該給你你想要

<html> 

<head></head> 

<body> 

    <form id="submitquery" method="get" action=""> 

    <?php 

     $month=array('[All Dates]','January','February','March','April', 
        'May','June','July','August', 
        'September','October','November','December'); 

     $language=array('[All Languages]','English','Portuguese','French','Italian','Japanese'); 

     $changeLanguagejs='changeForm();'; 
     $changeDatejs='this.form.submit();'; 

     writeSelect($language,'Language',$changeLanguagejs); 

     if (isset($_GET['Language'])){   
     if($_GET['Language']!='[All Languages]'){ 
      $training_sessions=filterLanguage($training_sessions);} 

     if (count($training_sessions)>=4){ 
     writeSelect($month,'Date',$changeDatejs); 
     if (isset($_GET['Date'])){ 
      if($_GET['Date']!='[All Dates]'){ 
       $training_sessions=filterDate($training_sessions);} 
     showResults($training_sessions);}} 
     else{showResults($training_sessions);}} 

    ?> 

    </form> 

</body> 

</html> 

<?php 

    function writeSelect($values,$name,$changejs){ 
     echo "\n".'<p>Select '.$name.':</p>'; 
     echo "\n".' <select id="training_sessions_'.$name.'" name="'.$name.'" onchange='.$changejs.'>'."\n"; 
     foreach($values as $value){    
     echo '  <option value="'.$value.'" ';    
     if (isset($_GET[$name]) && $_GET[$name]==$value){echo 'selected ';} 
     echo '>'.$value.'</option>'."\n";} 
     echo ' </select><br/><br/>'."\n";} 

    function filterLanguage($training_sessions){ 
     foreach($training_sessions as $key => $session){ 
     if($session['training_language']!=$_GET['Language']){ 
      unset($training_sessions[$key]);}} 
     return $training_sessions;} 

    function filterDate($training_sessions){ 
     foreach($training_sessions as $key => $session){ 
     if(date('F', strtotime($session['ZCS_b_date']))!=$_GET['Date']){ 
      unset($training_sessions[$key]);}} 
     return $training_sessions;} 

    function showResults($training_sessions){ 
     echo "\n".'Showing '.count($training_sessions).' '; 
     if(count($training_sessions)==1){echo 'Result';} 
     else{echo 'Results';} 
     echo'<br/>'."\n\n"; 
     print_r($training_sessions);} 

?> 

<script> 

    function changeForm(){ 
     var selectLang = document.getElementById("training_sessions_Language").value; 
     document.getElementById("submitquery").method="post"; 
     document.getElementById("submitquery").action="?Language="+selectLang; 
     document.getElementById("submitquery").submit();} 

</script> 

我要編輯出來的意見,使其更具可讀性...
結果查看評論回顧這個回答的編輯

+0

嗯,我會嘗試你的代碼。我怎麼解釋它。例如我有一個表與人名,語言他們知道,他們做的工作,和當他們開始這樣做的時候,我有下拉式過濾器來處理他們知道的語言,我想要做的是,當有4個以上的人知道英語時,我希望有一個新的過濾器可以按月過濾。我試圖弄清楚這一點。你現在明白我在這裏做什麼了嗎? – user3480148

+0

這使得更多的意義......我會稍後編輯我的答案當我有機會 – Swayze

+0

非常感謝,會是病人:) :) – user3480148