Reply
Expanding php search to two tables.
Old 04-17-2006, 01:31 PM Expanding php search to two tables.
mad_willsy's Avatar
Super Spam Talker

Posts: 774
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
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 
"&nbsp;";
                
$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!
__________________
Wont :P
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
When You Register, These Ads Go Away!
Reply     « Reply to Expanding php search to two tables.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10824 seconds with 12 queries