- Joined
- Apr 8, 2012
- Messages
- 235
- Reaction score
- 21
I've put an arcade games script on one of my domains. I had to change the code site wide for the script to work. For example: from <?=$siteurl?> to <?php echo $siteurl;?> but i'm stuck with the search feature. For instance, instead of getting the description of the searched game, I get this piece of code displaying: ' . $row['description'] . '
I'm pretty sure it's something simple that someone with PHP experience could figure out, however, I am willing to put my hand in my pocket if the price is right.
The domain is *****. Search for a game, eg: snake, to see the result.
Below is the source code for the search.php file.
<?php
include("config.php");
include("global.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $sitename;?></title>
<link rel="stylesheet" type="text/css" href="<?php echo $siteurl;?>style.css" />
</head>
<body>
<div id="header">
<div id="panic">
<a href="http://www.google.com"><img src="<?php echo $siteurl;?>/images/panic.png"
alt="<?php echo $sitename;?>" /></a>
</div>
<div id="logo">
<a href="<?php echo $siteurl;?>"><img src="<?php echo $siteurl;?>/images/logo.png"
alt="<?php echo $sitename;?>" /></a>
</div>
</div>
<div id="container"> <!-- coresponding </div> tag is missing -->
<div id="content"> <!-- coresponding </div> tag is missing -->
<div id="advertisement">
<?php echo $ads['header_ad'];?>
</div>
<?php include("sidebar.php");?>
<div id="right">
<!-- The original code that was above had to be changed on this page and site wide for
the script to work. For example:<?=$siteurl?> to <?php echo $siteurl;?>. I've managed to sort the rest
of the script, but I can't figure out this search feature -->
<!-- Code below needs fixed - this is the original code -->
<? if (isset($_GET['keyword'])) {
$keyword = clean_search($_GET['keyword']);
}
if(empty($keyword)) {
echo '<center>Search cannot be empty! please enter game ID or name to search for.</center>';
} else { ?>
<h2>Search Results for <?=$keyword?> </h2><br /><br />
<?
if(ctype_digit($keyword)) {
// We are searching by ID
$query = mysql_query("SELECT * FROM `games` WHERE `id` = '$keyword'");
} elseif(!ctype_digit($keyword)) {
// We are searching by Name or Desc
//$result = mysql_query("SELECT * FROM `games` WHERE `description` LIKE '%$keyword%' OR 'title' LIKE '%$keyword%'");
$query = mysql_query("SELECT * FROM games WHERE title LIKE '%$keyword%' OR description LIKE '%$keyword%' ORDER BY (CASE WHEN title LIKE '%$keyword%' THEN 1 ELSE 0 END) DESC limit 15");
}
if(mysql_num_rows($query) ==0) {
echo "<h2>Your search returned no results! <a href=\"index.php\">Try Again</a></h2>";
@mysql_close();
}
while($row = mysql_fetch_array($query)) {
echo '<table border="1" width="480" cellspacing="2" cellpadding="2" align="center">
<tr style="font-weight: bold;">
<td width="30" align="center">ID</td>
<td width="60" align="center">Thumbnail</td>
<td width="100" align="center">Title</td>
<td width="320" align="center">Description</td>
</tr>';
echo '<tr>
<td width="30" align="center">' . $row['id'] . '</td>
<td width="60" align="center"><a href="' . $siteurl . 'game/' . $row['id'] . '/"><img src="' . $row['thumbnail'] . '" style="height: 50px; width: 60px;" alt="' . $row['title'] . '" /></a></td>
<td width="100" align="center"></a> <strong><a href="' . $siteurl . 'game/' . $row['id'] . '/">' . $row['title'] . '</a></strong></td>
<td width="320" align="left">' . $row['description'] . '</td>
</tr>';
}
echo '</table><br /><div style="text-align:center;">';
}
echo '</div>';
include("footer.php");?>
I'm pretty sure it's something simple that someone with PHP experience could figure out, however, I am willing to put my hand in my pocket if the price is right.
The domain is *****. Search for a game, eg: snake, to see the result.
Below is the source code for the search.php file.
<?php
include("config.php");
include("global.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $sitename;?></title>
<link rel="stylesheet" type="text/css" href="<?php echo $siteurl;?>style.css" />
</head>
<body>
<div id="header">
<div id="panic">
<a href="http://www.google.com"><img src="<?php echo $siteurl;?>/images/panic.png"
alt="<?php echo $sitename;?>" /></a>
</div>
<div id="logo">
<a href="<?php echo $siteurl;?>"><img src="<?php echo $siteurl;?>/images/logo.png"
alt="<?php echo $sitename;?>" /></a>
</div>
</div>
<div id="container"> <!-- coresponding </div> tag is missing -->
<div id="content"> <!-- coresponding </div> tag is missing -->
<div id="advertisement">
<?php echo $ads['header_ad'];?>
</div>
<?php include("sidebar.php");?>
<div id="right">
<!-- The original code that was above had to be changed on this page and site wide for
the script to work. For example:<?=$siteurl?> to <?php echo $siteurl;?>. I've managed to sort the rest
of the script, but I can't figure out this search feature -->
<!-- Code below needs fixed - this is the original code -->
<? if (isset($_GET['keyword'])) {
$keyword = clean_search($_GET['keyword']);
}
if(empty($keyword)) {
echo '<center>Search cannot be empty! please enter game ID or name to search for.</center>';
} else { ?>
<h2>Search Results for <?=$keyword?> </h2><br /><br />
<?
if(ctype_digit($keyword)) {
// We are searching by ID
$query = mysql_query("SELECT * FROM `games` WHERE `id` = '$keyword'");
} elseif(!ctype_digit($keyword)) {
// We are searching by Name or Desc
//$result = mysql_query("SELECT * FROM `games` WHERE `description` LIKE '%$keyword%' OR 'title' LIKE '%$keyword%'");
$query = mysql_query("SELECT * FROM games WHERE title LIKE '%$keyword%' OR description LIKE '%$keyword%' ORDER BY (CASE WHEN title LIKE '%$keyword%' THEN 1 ELSE 0 END) DESC limit 15");
}
if(mysql_num_rows($query) ==0) {
echo "<h2>Your search returned no results! <a href=\"index.php\">Try Again</a></h2>";
@mysql_close();
}
while($row = mysql_fetch_array($query)) {
echo '<table border="1" width="480" cellspacing="2" cellpadding="2" align="center">
<tr style="font-weight: bold;">
<td width="30" align="center">ID</td>
<td width="60" align="center">Thumbnail</td>
<td width="100" align="center">Title</td>
<td width="320" align="center">Description</td>
</tr>';
echo '<tr>
<td width="30" align="center">' . $row['id'] . '</td>
<td width="60" align="center"><a href="' . $siteurl . 'game/' . $row['id'] . '/"><img src="' . $row['thumbnail'] . '" style="height: 50px; width: 60px;" alt="' . $row['title'] . '" /></a></td>
<td width="100" align="center"></a> <strong><a href="' . $siteurl . 'game/' . $row['id'] . '/">' . $row['title'] . '</a></strong></td>
<td width="320" align="left">' . $row['description'] . '</td>
</tr>';
}
echo '</table><br /><div style="text-align:center;">';
}
echo '</div>';
include("footer.php");?>
Last edited: