我正在尝试生成代码以使用嵌入 html 的 php 将信息从数据库提取到表中。
<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>
输出如下所示。
'; print ''; print '...'; print 'Questions and Answers'; print ''; while ($row = mysql_fetch_array($result)) { print ''; print 'Question' print ''.$row['question'].'' print ''; print ''; print 'Answer:'; print ''.$row['answer'].'' print ''; } print ''; mysql_close(); ?>
我做错了什么?
最佳答案
<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>
试试这个,我相信这是由于打印
关于php - PHP 将 MySQL 数据库提取到表中时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21009818/