搜索结果未显示

时间:2014-02-17 12:56:58

标签: php mysql search

我的search.php文件存在问题,无法呈现结果... 我没有得到任何错误字符串,但是当我输入现有关键字时,我没有得到任何结果...... 结果的格式与我在网站上的主要内容(网格视图)中查看的格式相同......

代码:

<body>
<?php include_once("analyticstracking.php") ?>

<div class='container'> <!--Start of the container-->

<div><?php include("includes/header.php"); ?></div>
<div><?php include("includes/navbar.php"); ?></div>
<div><?php include("includes/left_col.php"); ?></div>
<div class='main_col'>
<div class='main_content'>
<?php
include("includes/connect.php");

if(isset($_GET['search'])){

$search_id = $_GET['q'];

$search_query = "SELECT * FROM games WHERE game_keywords LIKE '%$search_id%'";

$run_query = mysql_query($search_query);

echo '<table>';
$games = 0;
while($search_row = mysql_fetch_array($run_query)){
// make a new row after 9 games
if($games%9 == 0) {
if($games > 0) {
// and close the previous row only if it's not the first
echo '</tr>';
}
echo '<tr>';
}
// make a new column after 3 games
if($games%3 == 0) {
if($games > 0) {
// and only close it if it's not the first game
echo '</td>';
}
echo '<td>';
}

$game_id = $search_row['game_id'];
$game_name = $search_row['game_name'];
$game_category = $search_row['game_name'];
$game_keywords = $search_row['game_name'];
$game_image = $search_row['game_image'];
?>
<div class="game_grid">
<a href="game_page.php?id=<?php echo $game_id; ?>"><img src="images/games_images/<?php echo $game_image; ?>" width="120" height="120" />
<span><?php echo $game_name; ?></span>
</div>
<?php 
$games++;  
}

}
?>
</table>

</div>
</div>
<div><?php include("includes/footer.php"); ?></div>

</div> <!--End of the container-->

</body>

有什么想法吗?

编辑: 我解决了我的问题,这是我犯的一个小错误, 在搜索的HTML表单中,我忘了提交提交按钮:&#34; name =&#34;搜索&#34;,我意外删除了...现在一切正常:)

2 个答案:

答案 0 :(得分:0)

您的代码输入错误 更改代码如下

if(isset($_GET['search'])){    
   $search_id = $_GET['search']; //$_GET['q'];
.
.
.    
}

答案 1 :(得分:0)

我解决了我的问题,这是我犯的一个小错误,在搜索的HTML表单中,我忘了提交提交按钮:“name =”search“,我意外删除了它......现在一切正常:)