2013-08-24 4 views
0

아래 코드에서 값을 검색 중이므로 결과가 표시되지만 값이 없으면 결과가 표시되지 않습니다. 내 경우에는 내가 실행하고 어떤 값을 검색하지 레코드가 표시됩니다. 아무도 도와주세요. 결과값을 검색하지 않고는 레코드를 표시하지 않습니다.

<form action="<?php echo site_url('search1_site/index');?>" method = "post"> 
    <input type="text" name = "keyword" /> 
    <input type="submit" id="opn" value = "Search" /> 
    </form> 




       <?php 
     if($results){ 
     ?> <div id='hideme'> 
     CLOSE<a href='#' class='close_notification' title='Click to Close'> 
     <img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/> 
     </a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" > 
     <table class="display2 table table-bordered table-striped"> 
     <tr> 

        <th>course_code</th> 
        <th>course name</th> 

       </tr> 
      <tr><?php 
     foreach ($results as $row) { 
      ?> 

     <td><?php echo $row->course_code;?></td> 
     <td><?php echo $row->course_name;?></td> 
     </tr> 
      <?php 
      } 
     }else{ 
    echo "no results"; 
     } 
     ?> 
    </table></div></div> 
    <script> 
    $('a.modal').bind('click', function(event) { 
    event.preventDefault(); 
    $('#modal').fadeIn(10); 
     }); 
function hide(obj) { 
    var el = document.getElementById(obj); 
    el.style.display = 'none'; 
     } 
</script> 
+0

[else 문이 표시됩니다] (http://stackoverflow.com/questions/18415474/else-statement-is-displaying) – Class

+0

'$ results'의 내용은 무엇입니까? – hallaji

답변

0

봅니다 버튼을 제출하고 그것이 if...else 블록 전에 설정되어 있는지 확인 당신에 name 속성을 추가.

<!-- HTML --> 
<input type="submit" name="submit" id="opn" value = "Search" /> 

// PHP 

<?php 
if (isset($_POST['submit'])) { // Here 
    // Do the search here 

     if($results){ 
     ?> <div id='hideme'> 
     CLOSE<a href='#' class='close_notification' title='Click to Close'> 
     <img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/> 
     </a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" > 
     <table class="display2 table table-bordered table-striped"> 
     <tr> 

        <th>course_code</th> 
        <th>course name</th> 

       </tr> 
      <tr><?php 
     foreach ($results as $row) { 
      ?> 

     <td><?php echo $row->course_code;?></td> 
     <td><?php echo $row->course_name;?></td> 
     </tr> 
      <?php 
      } 
     }else{ 
    echo "no results"; 
     } 
} // If closing 
?> 

이 항목과 비슷한가요?

+0

@moses, 내가 게시 한 코드는 양식을 제출할 때만 연구 조사를 표시합니다. 그게 네가 원하는게 아니야? 나는 당신의 다른 질문을 보았습니다. @ 클래스는 중복 된 것으로 표시했고, 이것도 제가 이해 한 것입니다. '$ result'가 어디에서 왔는지 더 설명해 주시겠습니까? 동일한 파일 또는 다른 파일 등의 질문에 코드가 있습니다. – vee

+0

지금 작동 중입니다. 감사합니다. – moses

0

변수 $results 인 경우 배열이 같은 것을 사용

if (count($results) > 0) 
{ 
// show results 
} else 
{ 
echo "No results"; 
} 
관련 문제