I have written a search box for
www.backthebulls.com. - Results page code as follows.
PHP Code:
<?php
if (!($page)){
$page = 1;}
$offset = ($page - 1) * $games_per_page;
$qstr = "SELECT * FROM games WHERE gName LIKE '%$search%' OR gID LIKE '%$search%' OR gDescription LIKE '%$search%'";
$count = 0;
$games = mysql_query($qstr);
while (list ($gameid, $GIncat, $gamename, $thumb, $description, $plays, $location, $eheight, $ewidth, $added) = mysql_fetch_row($games)){
?>
<?php
if ($count == 2) {
?>
<tr align="left" valign="top">
<?php
}
?>
<td align="center"><span class="normalText">
<?php
if ($seo_support == 1){ echo "<a href=\"play-$gameid.html\">"; } else {
echo "<a href=\"ply.php?id=$gameid\">";}
?>
<img src="../images/upload/<?php echo"$thumb"; ?>" alt="<?php echo"$gamename"; ?>" border="0" height="60" width="60"></span></td>
<td class="normalText" width="33%"> <b>
<?php
if ($seo_support == 1){ echo "<a href=\"play-$gameid.html\">"; } else {
echo "<a href=\"ply.php?id=$gameid\">";}
?>
<?php echo"$gamename"; ?> </b><br>
<?php echo"$description"; ?><br>
<?php
if ($seo_support == 1){ echo "<a href=\"play-$gameid.html\" class=gameLink>"; } else {
echo "<a href=\"ply.php?id=$gameid\" class=gameLink>";}
?>
<b>Play now!</b> </td>
<?php
if ($count == 1) {
?>
</tr>
<?php
}
?>
<?php
if ($count == 2) {
$count = $count -1;
}elseif ($count == 0){
$count = $count +1;
}else {
$count = $count +1;
}
} ?>
</tbody>
</table> <?php
$numgames = mysql_query("SELECT * FROM `games` where `gInCategory` = '$cid'");
$numrows = mysql_num_rows($numgames);
$ii = ceil($numrows / $games_per_page);
$iq = 1;
if ($ii != 1)
{
while ($iq <= $ii)
{
if ($iq != $page)
{
echo "<a href=";
echo $_SERVER['PHP_SELF'];
echo "?page=";
echo $iq;
echo "&cid=";
echo $cid;
echo ">";
}
echo "[";
echo $iq;
echo "]";
if ($iq != $page)
{
echo "</a>";
}
echo " ";
$iq++;
}
}
echo $lowerpage;
echo $upperpage;
?>
How do I extend the query...
Code:
SELECT * FROM games WHERE gName LIKE '%$search%' OR gID LIKE '%$search%' OR gDescription LIKE '%$search%'
...to link table 'games' to the table 'categories' (fields 'gInCategory' 'and cId')
(also adding or cName LIKE '%$search%' to endo of query when it is linked)
add this to this while...
PHP Code:
while (list ($gameid, $GIncat, $gamename, $thumb, $description, $plays, $location, $eheight, $ewidth, $added) = mysql_fetch_row($games)){
...as variables $cid and $cname.
DB INFO:
Table, 'games' has the fields 'gId', 'gInCategory', 'gName', 'gThumb', 'gDescription', 'gplays', 'location', 'EmbedHeight', 'EmbedWidth' and 'added'
Table, 'categories' has the fields 'cId', 'cName' and 'order'
THANKS IN ADVANCE!
NOTE: Major helpers (so far CHRODER) will be noted on website after launch!