2016-11-07 1 views
3

안녕하세요! PHP와 결합 된 HTML 표가 있습니다. 내가 원하는 것은 당신이 데이터베이스에 새로운 데이터를 입력 할 때 새로운 데이터를 표시하기 위해 테이블이 새로 고쳐 지지만 테이블의 나머지 부분 만 표시된다는 것입니다. 솔직히 필자는 프로그래머가 아니지만 JSON과 Ajax를 사용할 수 있지만 어떻게 작동하는지 이해하지 못했습니다. 누군가가 시간과 인내심을 가지고 있다면 나는 그것을 얼마나 고맙게 생각하는지 말해 준다. 전체 페이지가 아닌 HTML 테이블 만 새로 고침

내 PHP 코드입니다 :

<?php 
// ----------- CONEXIÓN ------------------ 
    require 'RecibeConsultaPuenteConexion.php'; 
    //echo "Conexión OKAS <br />"; 
    // ----------- TRAYENDO DATOS ------------------  
    $statement = $conexion->query('SELECT * FROM tbl_consultas'); 
    $statement->execute(); 


$resultados = $statement->fetchAll(); 
foreach ($resultados as $fila) { 



} 





// json_encode($fila); 


?> 

그리고 이것은 내 HTML 코드입니다 :

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" > 
    <table class="Pizarra" id="pizarra" name="pizarra" cellspacing="0px";> 
     <tr class="trThDos"> 
     <th></th> 
     <th></th> 
     <th></th> 
     <th></th> 
     <th></th> 
     </tr> 
     <tbody> 
     <!-- Comienza PHP --> 
     <?php 
     $i = 0; 
     foreach ($resultados as $fila) { 
     ?> 
      <tr class="trPizarra" id="trPizarra"> 

      <td class="tdTurno" style="text-align:center;"><?php echo '#' . ++$i ?></td> 

      <td class="tdImg" style="text-align:center;"><?php echo $fila ['asunto']; 

        switch ($fila['asunto']){ 

        case "0": 
        echo "<img src='./img/consulta-56-2.png' title=\"Consulta.\" height=\"32\" width=\"32\">"; 
        break; 

        case "1": 
        echo "<img src='./img/shot-56-2.png' title=\"Inyección.\" height=\"32\" width=\"32\">"; 
        break; 

        case "2": 
        echo "<img src='./img/ta-56-2.png' title=\"Toma de presión.\" height=\"32\" width=\"32\">"; 
        break; 

        case "3": 
        echo "<img src='./img/cert-56-2.png' title=\"Certificado médico.\" height=\"32\" width=\"32\">"; 
        break; 

        case "4": 
        echo "<img src='./img/consulta-56-4.png' title=\"Consulta ⬇ abajo.\" height=\"32\" width=\"32\">"; 
        break; 

        case "5": 
        echo "<img src='./img/shot-56-4.png' title=\"Inyección ⬇ abajo.\" height=\"32\" width=\"32\">"; 
        break; 

        case "6": 
        echo "<img src='./img/ta-56-4.png' title=\"Toma de presión ⬇ abajo.\" height=\"32\" width=\"32\">"; 
        break; 

        case "7": 
        echo "<img src='./img/cert-56-4.png' title=\"Certificado médico ⬇ abajo.\" height=\"32\" width=\"32\">"; 
        break; 

        default: 
        echo "Hubo un error en la selección de asunto"; 
        break; 

        } ?></td> 

      <td class="tdNombre" id="tdNombre" style="text-align:center;"><?php echo $fila ['nombre_completo']; ?></td> 

      <td class="tdHr" style="text-align:center;"><?php echo $fila ['hora']; ?> <span class="icon icon-stopwatch"></span></td> 

      <td class="td-aceptar"> 
      <a class="aceptar-a" id="aceptar-a" href="http://localhost/FARMAXIA/index.php?id=<?php echo $fila['ID']; ?>" title="Aceptar paciente." > 
      <button class="btn btn-xs" id="aceptar-btn" ><span class="glyphicon glyphicon-ok"></span> Aceptar</button> 
      </a> 
      </td> 

      </tr> 
     <?php } ?> 
     <!-- Terminó PHP --> 
      <tfoot class="tableFoot"> 
       <tr> 
        <td colspan="5"><p>&nbsp;</p></td> 
       </tr> 
      </tfoot> 

     </tbody> 
    </table> 
    </form> 
+0

Ajax/JSON으로 처음 시도한 내용은 무엇입니까? 아무 것도 없다면 간단한 튜토리얼을보고 직접 구현할 수 있는지 확인하십시오. – Jhecht

+0

jquery datatable을 사용해 보시지 않겠습니까? 자동으로 상쾌하게 처리합니다. – Iftikhar

답변

2

기본적인 뼈에 노출 된 코드는이

당신의 jQuery 코드

//asuming you want to refresh your table every 5 sec 
function refresh_table() 
{ 
    $.ajax({ 
     type:"POST", 
     url:"my_refresh_php_code.php", 
     cache:false, 
     success:function(html){ // html returns the code outputted from the below php script 
      $("my_table_class_or_id").html(html); //replace your table html with the new one 
     } 
    }) 
} 

setInterval(refresh_table, 5000); 

"my_ refresh_php_code.php "스크립트

<?php 

//output the data you want your table to be refreshed with 
echo "my text" 

?> 
+0

도움을 많이 주셔서 감사합니다. 완벽하게 작동합니다! – Emm

관련 문제