gpt4 book ai didi

php - 在表中查看mysql数据库查询到的数据

转载 作者:行者123 更新时间:2023-11-29 22:04:49 25 4
gpt4 key购买 nike

我正在尝试更新网页搜索功能的代码,但现在它没有返回任何内容。我已经使用它有一段时间了,但没有从中得到任何东西。

这是 HTML 搜索代码:

<form method="post" action="words_results1.php">
<table align="center">
<tr>
<td>Keyword</td>
<td><input type="text" name="Keyword" /></td>
</tr>
<tr>
<td>Author</td>
<td><input type="text" name="Author" /></td>
</tr>
<tr>
<td valign=bottom>Words Posted<BR />on or before</td>
<td valign=top>
<table>
<tr>
<td width="33%">Day</td>
<td width="33%">Month</td>
<td width="34%">Year</td>
</tr>
<tr>
<td>
<select name=Day>
<?php
echo '<option></option>';
for($count = 1; $count <= 31; ++$count)
{
echo "<option>$count</option>";
}
?>
</select>
</td>
<td>
<select name=Month>
<?php
echo '<option></option>';
for($count = 1; $count <= 12; $count++)
{
echo "<option value=$count>".date("M", mktime(0,0,0,$count,1, 2000))."</option>";
}
?>
</select>
</td>
<td>
<select name=Year>
<?php
echo '<option></option>';
for($count = date("Y"); $count >= 1997; $count--)
{
echo "<option>$count</option>";
}
?>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan=2 align=center>
&nbsp;<BR />
<input type="submit" value="Search" />
&nbsp;&nbsp;&nbsp;
<input type="submit" name="cancel" value="Cancel" />
</td>
</tr>
</table>
</form>

PHP

<?php 

if(isset($_POST['cancel']))
{
echo("index.html");
exit;
}

$qry_string = "SELECT * FROM Words";
$search = "";

if(!empty($Keyword))
{
$End_String = "(Word LIKE '%$Keyword%' OR Title LIKE '%$Keyword%')";
$search .="&Keyword=$Keyword";
}

if(!empty($Author))
{
if(isset($End_String))
{
$End_String .= " AND (Author LIKE '%$Author%')";
}
else
{
$End_String = "(Author LIKE '%$Author%')";
}
$search .="&Author=$Author";
}

if(!empty($Day))
{
if(isset($End_String))
{
$End_String .= " AND (DAYOFMONTH(Date_Created) = '$Day')";
}
else
{
$End_String = "(DAYOFMONTH(Date_Created) = '$Day')";
}
$search .="&Day=$Day";
}

if(!empty($Month))
{
if(isset($End_String))
{
$End_String .= "AND (MONTH(Date_Created) = '$Month')";
}
else
{
$End_String = "(MONTH(Date_Created) = '$Month')";
}
$search .="&Month=$Month";
}

if(!empty($Year))
{
if(isset($End_String))
{
$End_String .= " AND (YEAR(Date_Created) = '$Year')";
}
else
{
$End_String = "(YEAR(Date_Created) = '$Year')";
}
$search .="&Year=$Year";
}

if (!isset($offset)) $offset=0;

if(isset($End_String))
{
$qry_string = $qry_string." WHERE ".$End_String . " ORDER BY Date_Created DESC LIMIT $offset,101";
}
else
{
$qry_string = $qry_string." ORDER BY Date_Created DESC LIMIT $offset,101";
}

// echo $qry_string . "<P><HR><P>";
$result = mysql_query($qry_string);
echo mysql_error();
?>

最后一点是形成表格的代码,我假设问题出在此处,但老实说目前还不确定

<table style="margin: 5px 15px; 5px 20px;" align="center" bgcolor="#666666" border="0" cellpadding="3" cellspacing="1">
<tbody><tr style="background: #04C1DE; font-family: Verdana; font-weight: bold; font-size: 18px;">
<td style="width: 50%; padding: 5px;">
Word
</td>
<td style="width: 20%; padding: 5px;">
Author
</td>
<td style="width: 10%; padding: 5px;">
Date
</td>
<td>Category</td>
<td>Active?</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>

</tr>

<?php
$count = 1;
$bgc = 0;


while($row = mysql_fetch_array($sql))
{
if ($count > 100) break;
echo '<tr style="background: ';
if ($bgc==0) echo "#FFFFFF";
else echo "#CFEBFD";
$bgc == 0?$bgc=1:$bgc=0;
echo ';">';
echo "<td><a href=../../words/display_word.php?ID=$row[ID]>$row[Title]</a></td>";
echo "<td>$row[Author]</td><td>$row[Display_Date]</td><td>$row[category]</td>";
if($row[active])
{
echo "<td>YES</td>";
}
else
{
echo "<td>NO</td>";
}
echo "<td>$row[link_count]</td>";
if($row[Title] != "")
{
echo "<td><a href=words_edit.html?ID=$row[ID]>Edit</a></td></tr>";
}
else
{
echo "</tr>";
}
$count++;
}
?>

最佳答案

看来,你没有收集到的值(value)

$Keyword=$_POST['Keyword'];

并添加关闭表格标签以正确以表格格式显示结果。

关于php - 在表中查看mysql数据库查询到的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32255887/

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