2014-03-29 47 views
-2

我想創建一個顯示php sql查詢結果的html表。它是學生PHP代碼的結果頁是下如何在html表中使用sql查詢結果

$r1=$_GET["r"]; 
$con=mysqli_connect(localhost,chumspai_tlss,Tls121,chumspai_tlsResult); 

if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
$result = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE sr_='$r1'"); 

while($row = mysqli_fetch_array($result)) 
{ 

HTML代碼

<pre> 
<form name="frmResult" id="frmResult" action="" method="post" onsubmit="return checkEmpty();"> 
    <table width="80%" cellpadding="5" cellspacing="5" border="0"> 
    <tr> 
     <td class="heading noborder">Enter Your Roll Number:</td> 
     <td class="noborder"><input type="text" id="r" name="r" value="" /></td> 
    </tr> 
    <tr> 
    <!-- 
     <td class="heading noborder">Enter Your Name:</td> 
     <td class="noborder"><input type="text" id="name" name="name" value="" /></td> 
    </tr> 
    <tr> 
     <td class="heading noborder">Search by</td> 
     <td class="noborder"><input type="radio" id="option" name="option" value="rno" checked="checked" /> 
     Roll No 
     <input type="radio" id="option" name="option" value="name" /> 
     Name </td> 
    </tr> 
    --> 
    <tr> 
     <td class="noborder">&nbsp;</td> 
     <td class="noborder"><input type="submit" name="submit" value="Search" /> 
     <input type="reset" name="reset" value="Clear" /> 
     </td> 
    </tr> 

    <!--<tr> 
     <td colspan="2"> <embed src="images/wait.swf"></embed></td> 
    </tr> --> 
    </table> 
</form> 

        <div style="border:1px solid #000000;"> 
        <table width="100%" cellpadding="10" cellspacing="0" border="0"> 
         <tr> 
         <td class="heading grey" width="30%">RNO</td> 
         <td><?php 
         Print $row['sr_']; 
         ?> 
         </td> 
         </tr> 
         <tr> 
         <td class="heading grey">NAME</td> 
         <td class="shade"></td> 
         </tr> 
         <tr> 
         <td class="heading grey">FATHER</td> 
         <td></td> 
         </tr> 

         <tr> 
         <td class="heading grey">regno</td> 
         <td></td> 
         </tr> 
        </table> 

        <table width="100%" cellpadding="10" cellspacing="0" border="0"> 
         <tr class="grey"> 
         <td rowspan="2" class="heading">Sr.no </td> 
         <td rowspan="2" class="heading">Name of subject </td> 
         <td rowspan="2" class="heading">Maximum Marks</td> 
         <td colspan="7" class="heading">detail of marks Obtained</td> 
         <tr class="grey"> 
         <td class="heading">PART ONE</td> 

         <td class="heading">Total</td> 
         </tr> 
         <tr> 
         <td>1</td> 
         <td>Urdu</td> 

         <td></td> 
         <td>&nbsp;</td> 
         <td></td> 
         </tr> 
         <tr class="shade"> 
         <td>2</td> 
         <td>English</td> 

         <td></td> 
         <td>&nbsp;</td> 
         <td></td> 
         </tr> 
         <tr> 
         <td>3</td> 
         <td>Islamyat</td> 

         <td></td> 
         <td>&nbsp;</td> 
         <td></td> 
         </tr> 
         <tr class="shade"> 
         <td>4</td> 
         <td>pakstudies</td> 

         <td></td> 
         <td>&nbsp;</td> 
         <td></td> 
         </tr> 

         <tr class="shade"> 
         <td>6</td> 
         <td></td> 

         <td></td> 
         <td></td> 
         <td>0</td> 
         </tr> 
         <tr> 
         <td>7</td> 
         <td></td> 

         <td></td> 
         <td></td> 
         <td>0</td> 
         </tr> 
         <tr class="shade"> 
         <td>8</td> 
         <td></td> 

         <td></td> 
         <td></td> 
         <td>0</td> 
         </tr> 
         <tr class="shade"> 
         <td>9</td> 
         <td></td> 

         <td></td> 
         <td></td> 
         <td>0</td> 
         </tr> 
         <tr class="grey"> 
         <td colspan="2" class="heading">TOTAL</td> 
         <td class="heading">1100</td> 
         <td colspan="4" class="heading"></td> 
         </tr> 
         <tr class="grey"> 
         <td colspan="3" class="heading">NOTIFICATION</td> 
         <td class="heading"></td> 
         <td class="heading"></td> 
         <td colspan="2" class="heading"></td> 
         </tr> 
         <tr> 
          <td colspan="7">(i) This provisional result intimation is issued as a notice only. Errors and omissions are excepted.</td> 
         </tr> 
        </table> 
</pre> 

請幫我如何嵌入這個HTML表格和HTML表單還這個PHP查詢。

+1

認爲你錯過了你的代碼...什麼是在'而($行= mysqli_fetch_array($結果))'...? – webeno

回答

0

試試這個:

 $result = mysql_query("select * from emp"); 
     while($row = mysql_fetch_array($result)) 
    { 
     echo "<tr>";    
      echo "<td id=SrNo$cnt >".$row['eno']."</td>";    
      echo "<td id=ItemId$cnt >".$row['eId']."</td>";    
      echo "<td>". "<button name='Update' id='update' onclick='show(".$cnt.")'>UPDATE</button>"."</td>"; 
      echo "<td>". "<button name='Report' id='show' onclick='Report(".$row['SrNo'].")'>REPORT</button>"."</td>"; 
      echo "</tr>"; 
      echo "<div id=show$cnt>"; 
      echo "</div>"; 
      $cnt++; 
} 
2

你不是那麼遠。

變量$ row是一個包含數據的數組。試試這個來看看它在你的呼叫中的結構:

print_r($row); 

使用這個命令,你會看到你的數組中的每個項目的名稱。在某處注意它。然後你可以做這樣的事情:

...<td><?php echo $row['desired_column_name']; ?></td>... 

如果你從你的mysql查詢接收數據,這應該做的伎倆。

希望它能幫助, 保羅

相關問題