2014-01-09 56 views
0

我想要生成代碼以使用PHP嵌入在HTML中將數據庫中的信息提取到表中。PHP將MySQL數據庫提取到表中的問題

<div class="entry"> 
<?php 
    $host="localhost"; 
    $user=""; 
    $password=""; 
    $dbname = ""; 
    mysql_connect($host,$user,$password); 
    mysql_select_db($dbname) or die("Unable to select database"); 
    $query = "SELECT * FROM QA"; 
    $result = mysql_query($query); 
    $info = mysql_fetch_array($result); 
    print '<table="1">'; 
    print '<tr>'; 
    print  '<th>...</th>'; 
    print  '<th>Questions and Answers</th>'; 
    print '</tr>'; 
    while ($row = mysql_fetch_array($result)) 
    { 
    print '<tr>'; 
    print '<td>Question</td>' 
    print '<td>'.$row['question'].'</a></td>' 
    print '</tr>'; 
    print '<tr>'; 
    print '<td>Answer:</td>'; 
    print '<td>'.$row['answer'].'</a></td>' 
    print '</tr>'; 
    } 
    print '</table>'; 
    mysql_close(); 
    ?> 
    </div> 

輸出如下所示。

';打印'';打印'...';打印「問題與解答」;打印''; while($ row = mysql_fetch_array($ result)){print'';打印'問題'打印''。$ row ['question']。''打印'';打印'';打印'答案:'; print''。$ row ['answer']。''print''; } print''; mysql_close(); ?>

我在做什麼錯?

+1

使用回聲無法打印 – Rottingham

+0

不要使用廢棄的函數 – Strawberry

+0

不,這是有效的'打印的「Hello world」;'@LouisXIV –

回答

0
<div class="entry"> 
<?php 
    $host="localhost"; 
    $user=""; 
    $password=""; 
    $dbname = ""; 
    mysql_connect($host,$user,$password); 
    mysql_select_db($dbname) or die("Unable to select database"); 
    $query = "SELECT * FROM QA"; 
    $result = mysql_query($query); 
    $info = mysql_fetch_array($result); 
    echo '<table="1">'; 
    echo '<tr>'; 
    echo  '<th>...</th>'; 
    echo  '<th>Questions and Answers</th>'; 
    echo '</tr>'; 
    while ($row = mysql_fetch_array($result)) 
    { 
    echo '<tr>'; 
    echo '<td>Question</td>' 
    echo '<td>'.$row['question'].'</a></td>' 
    echo '</tr>'; 
    echo '<tr>'; 
    echo '<td>Answer:</td>'; 
    echo '<td>'.$row['answer'].'</a></td>' 
    echo '</tr>'; 
    } 
    echo '</table>'; 
    mysql_close(); 
    ?> 
    </div> 

試試這個我相信這是由於PRINT

相關問題