gpt4 book ai didi

php - 如何显示特定div中的mysql表?

转载 作者:行者123 更新时间:2023-11-29 13:56:34 25 4
gpt4 key购买 nike

我有一个页面,用户在其中搜索 pdf,结果显示在该页面中,但在特定的 div 中..显示了表格,但页面的整个设计被破坏了...任何人都可以指出我我在这里做错了什么?

    <div id="content">
<div class="post">
<div class="entry">
<form name="search" action="" method="post">
<input type="text" class="search" name="searchbox" id="searchbox" />
<input type="submit" name="search" id="search" value="Search" />
</form>

</div>
</div>

<div class="post">
<div class="entry">
<?php
if(isset($_REQUEST['search'])){
$searchterm = $_REQUEST['searchbox'];
$sql = "select name,size from ebooks where name like '%$searchterm%'";
$result=mysql_query($sql);
if(!($result)){
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++){
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result)){
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);

}
?>
</div>

</div>

最佳答案

您的 table 不近</table>不?

这里是正确的代码:

<?php
if (isset($_REQUEST['search'])) {

$searchterm = $_REQUEST['searchbox'];
$sql = "SELECT `name`, `size` FROM `ebooks` WHERE `name` LIKE '%$searchterm%'";
$result = mysql_query($sql);

if (!($result)){
die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);
echo "<table border=\"1\">\n<tr>";

for ($i=0; $i<$fields_num; $i++) {
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}

echo "</tr>\n";

while ($row = mysql_fetch_row($result)) {
echo "<tr>";
foreach($row as $cell) {
echo "<td>$cell</td>";
}
echo "</tr>\n";
}

echo "</table>\n";

mysql_free_result($result);
}
?>

关于php - 如何显示特定div中的mysql表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15763493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com