2016-04-03 24 views
0

2 tabloyu index.php içinde görüntülemek istedim. Aynı verileri 1 veritabanından görüntüleyin. Ama görünmüyor. Buradadisplay 2 tablosunu index.php içinde bulabilirsiniz mysql

click here to see image

ve aşağıdaki görüntü benim kodu (index.php)

<?php 
 

 
\t include("dbcon.php"); \t 
 
\t 
 
\t $link=$cn; 
 
    $i=0; 
 
\t $result=mysqli_query($link,"SELECT * FROM `node` ORDER BY `tarikh` DESC LIMIT 1"); 
 
\t 
 
?> 
 

 
<html> 
 
    <head> 
 
     <title>Sensor Data1</title> 
 
     <meta http-equiv="refresh" content="30"> 
 
    </head> 
 
<body> 
 
    <Center><h1>Sensor Readings</h1> 
 
    <h1>Node 1</h2> 
 

 

 
    <table border="2" cellspacing="2" cellpadding="2"> 
 
\t \t <tr> 
 
\t \t \t <td>&nbsp;No&nbsp;</td> 
 
\t \t \t <td>&nbsp;Waktu/Tarikh&nbsp;</td> 
 
\t \t \t <td>&nbsp;Temperature &nbsp;</td> 
 
\t \t \t <td>&nbsp;Humidity &nbsp;</td> 
 
\t \t \t <td>&nbsp;Length(CM)&nbsp;</td> 
 
\t \t \t <td>&nbsp;Node&nbsp;</td> \t 
 
\t \t </tr> 
 

 
\t \t 
 
     <?php 
 
\t \t  while($row = mysqli_fetch_array($result)) { 
 
\t \t   printf("<tr><td> &nbsp;%d </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td></tr>", 
 
\t \t   ++$i, $row["tarikh"], $row["temperature"], $row["humidity"], $row["height"], $row["node"]); 
 
\t \t  } \t \t 
 
\t \t 
 
     ?> 
 

 
    </table></center> 
 
    
 
    <center><table border="2" cellspacing="2" cellpadding="2"> 
 
\t \t <tr> 
 
\t \t \t <td>&nbsp;No&nbsp;</td> 
 
\t \t \t <td>&nbsp;Waktu/Tarikh&nbsp;</td> 
 
\t \t \t <td>&nbsp;Temperature &nbsp;</td> 
 
\t \t \t <td>&nbsp;Humidity &nbsp;</td> 
 
\t \t \t <td>&nbsp;Length(CM)&nbsp;</td> 
 
\t \t \t <td>&nbsp;Node&nbsp;</td> \t 
 
\t \t </tr> 
 
\t \t 
 
\t \t <?php 
 
\t \t  while($row = mysqli_fetch_array($result)) { 
 
\t \t   printf("<tr><td> &nbsp;%d </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td></tr>", 
 
\t \t   ++$i, $row["tarikh"], $row["temperature1"], $row["humidity1"], $row["height"], $row["node"]); 
 
\t \t  } \t \t 
 
\t \t 
 
     ?></center> 
 
</body> 
 
</html>

göründüğü yapmak için kodumu düzeltebilirsiniz olduğunu görüyor musunuz?

cevap

0

Sanırım ikinci tablonun baskı yapmamasının sebebi, $ while sonucunun ilk döngünün sonuna gelmesiydi.

Eğer haklıysam, hızlı ve kolay çözüm sql sorgusunu aşağıdaki gibi ikinci döngüden önce yeniden çalıştırmak olacaktır. Bunu kullandım tamamladıktan hiç rağmen

<?php 
 

 
\t include("dbcon.php"); \t 
 
\t 
 
\t $link=$cn; 
 
    $i=0; 
 
\t $result=mysqli_query($link,"SELECT * FROM `node` ORDER BY `tarikh` DESC LIMIT 1"); 
 
\t 
 
?> 
 

 
<html> 
 
    <head> 
 
     <title>Sensor Data1</title> 
 
     <meta http-equiv="refresh" content="30"> 
 
    </head> 
 
<body> 
 
    <Center><h1>Sensor Readings</h1> 
 
    <h1>Node 1</h2> 
 

 

 
    <table border="2" cellspacing="2" cellpadding="2"> 
 
\t \t <tr> 
 
\t \t \t <td>&nbsp;No&nbsp;</td> 
 
\t \t \t <td>&nbsp;Waktu/Tarikh&nbsp;</td> 
 
\t \t \t <td>&nbsp;Temperature &nbsp;</td> 
 
\t \t \t <td>&nbsp;Humidity &nbsp;</td> 
 
\t \t \t <td>&nbsp;Length(CM)&nbsp;</td> 
 
\t \t \t <td>&nbsp;Node&nbsp;</td> \t 
 
\t \t </tr> 
 

 
\t \t 
 
     <?php 
 
\t \t  while($row = mysqli_fetch_array($result)) { 
 
\t \t   printf("<tr><td> &nbsp;%d </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td></tr>", 
 
\t \t   ++$i, $row["tarikh"], $row["temperature"], $row["humidity"], $row["height"], $row["node"]); 
 
\t \t  } \t \t 
 
\t \t 
 
     ?> 
 

 
    </table></center> 
 
    
 
    <center><table border="2" cellspacing="2" cellpadding="2"> 
 
\t \t <tr> 
 
\t \t \t <td>&nbsp;No&nbsp;</td> 
 
\t \t \t <td>&nbsp;Waktu/Tarikh&nbsp;</td> 
 
\t \t \t <td>&nbsp;Temperature &nbsp;</td> 
 
\t \t \t <td>&nbsp;Humidity &nbsp;</td> 
 
\t \t \t <td>&nbsp;Length(CM)&nbsp;</td> 
 
\t \t \t <td>&nbsp;Node&nbsp;</td> \t 
 
\t \t </tr> 
 
\t \t 
 
\t \t <?php 
 

 

 
\t \t  $result=mysqli_query($link,"SELECT * FROM `node` ORDER BY `tarikh` DESC LIMIT 1"); 
 
\t 
 
\t \t  while($row = mysqli_fetch_array($result)) { 
 
\t \t   printf("<tr><td> &nbsp;%d </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td></tr>", 
 
\t \t   ++$i, $row["tarikh"], $row["temperature1"], $row["humidity1"], $row["height"], $row["node"]); 
 
\t \t  } \t \t 
 
\t \t 
 
     ?></center> 
 
</body> 
 
</html>

(Ben sadece bir $ sonucunu sıfırlamak için hızlı arama ile buldum). mysqli_data_seek ($ sonuç, 0) kullanabilir; Daha hızlı olurdu, verileri yeniden getirmeye gerek olmadığı gibi düşünüyorum.