| Welcome to Webforumz.com. |
|
Apr 26th, 2008, 13:56
|
#1 (permalink)
|
|
Lead Administrator
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,063
|
Search suggestions
i wanted to make a search engine for my site ( and before you go on about google, i dont want it )
i have something very specific in mind, i want the search to include Search Suggestions alot like ask.com
so when they start typing, possible results come up,
let me show you what i have
my table is as follows
- Code: Select all
CREATE TABLE `recipes` (
`Id` mediumint(13) NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`yield` varchar(255) NOT NULL default '',
`instructions` text NOT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=315743 ;
and i am going to make the results display within my sites template, linking to anther file that will pull the choosen result and display the recipe
so it is really just a search engine for my own site i suppose with Search suggestions
these results are coming from my database, does anyone know how this can be done ?
cheers
|
|
|
Apr 26th, 2008, 14:40
|
#2 (permalink)
|
Join Date: Jun 2007
Location: uk
Posts: 459
|
Re: Search suggestions
dont know about the search suggestions.
the actual search engine itself I might be able to help with.
I built one for my wifes site if you want to check it out.
|
|
|
Apr 26th, 2008, 14:47
|
#3 (permalink)
|
|
Lead Administrator
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,063
|
Re: Search suggestions
its nice, if it grabs the information from the database its perfect, thank you
i think the search suggestions will more than likely be a little harder
cheers
|
|
|
Apr 26th, 2008, 14:49
|
#4 (permalink)
|
Join Date: Jun 2007
Location: uk
Posts: 459
|
Re: Search suggestions
Yes it grabs all the info from my Mysql database. I think the image is linked at the moment but anything grabbed from the database can be linked.
|
|
|
Apr 26th, 2008, 14:58
|
#5 (permalink)
|
|
Lead Administrator
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,063
|
Re: Search suggestions
although the image is a very cool idea, unfortunetly at the moment, my database has no images, would be cool for the future though,
( i cant add images to them all as the database has 317,682 recipes )
please if you are willing, post either the code or the zip here,
cheers
|
|
|
Apr 26th, 2008, 15:00
|
#6 (permalink)
|
Join Date: Jun 2007
Location: uk
Posts: 459
|
Re: Search suggestions
Give me 10mins while i remove all my connection info.
|
|
|
Apr 26th, 2008, 15:11
|
#7 (permalink)
|
Join Date: Jun 2007
Location: uk
Posts: 459
|
Re: Search suggestions
heres the code.
- PHP: Select all
<?php require_once('Connections/yourconnection.php');
mysql_select_db($database_yours, $yours); ?> <?php $currentPage = $_SERVER["PHP_SELF"];
$maxRows_Recordset1 = 5; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$colname_Recordset1 = "-1"; if (isset($_GET['textfield'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['textfield'] : addslashes($_GET['textfield']); } mysql_select_db($database_yours, $yours); $query_Recordset1 = sprintf("SELECT item_title, item_price, item_desc, item_image, hyper_link, `sql search` FROM store_items WHERE `sql search` LIKE '%%%s%%'", $colname_Recordset1); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $sensuallad) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?>
Put this at the top of your results.php page. Just alter query recordset1 to your table fields.
Then the below code where you want the results to show.
- PHP: Select all
<?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <?php do { ?> <table width="100%" border="1"> <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <tr> <td><a href="<?php echo $row_Recordset1['hyper_link']; ?>"><img src="<?php echo $row_Recordset1['item_image']; ?>" alt="" name="sensual" style="width:100px; height:100px;" border="0"></a></td> <td width="20%" style="padding-left:4px;"><a href="<?php echo $row_Recordset1['hyper_link']; ?>"><span class="style5"><?php echo $row_Recordset1['item_title']; ?></span></a></td> <td style="padding-left:4px; padding-right:4px;"><a href="<?php echo $row_Recordset1['hyper_link']; ?>"><span class="style2"><?php echo $row_Recordset1['item_desc']; ?></span></a></td> <td style="padding-left:4px; padding-right:4px;"><a href="<?php echo $row_Recordset1['hyper_link']; ?>"><span class="style2">£<?php echo $row_Recordset1['item_price']; ?></span></a></td> </tr> </table>
<?php } // Show if recordset not empty ?> <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <?php } // Show if recordset not empty ?> <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <br /> <?php } // Show if recordset not empty ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><br> Back </a> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a> <?php } // Show if recordset not empty ?></div> <?php } // Show if recordset not empty ?> <p align="center" ><?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <span class="style43Copy">Page:</span> <?php for ($i=0; $i <= $totalPages_Recordset1; $i++) { $TFM_PagesEndCount = $i + 1; if($i != $pageNum_Recordset1) { printf('<a href="'."%s?pageNum_Recordset1=%d%s", $currentPage, $i, $queryString_Recordset1.'">'.$TFM_PagesEndCount."</a>"); }else{ echo("<strong>$TFM_PagesEndCount</strong>"); } if($i != $totalPages_Recordset1) echo(" "); } ?> <?php } // Show if recordset not empty ?>
Sorry the display is coded in tables im sure it wouldnt be to difficult to change to css, I just havent bothered 
|
|
|
Apr 26th, 2008, 15:11
|
#8 (permalink)
|
|
Lead Administrator
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,063
|
Re: Search suggestions
very cool thank you,
just need a search suggestions script now if anyone knows one
|
|
|
Apr 26th, 2008, 15:26
|
#9 (permalink)
|
|
Lead Administrator
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,063
|
Re: Search suggestions
oh, i have found one, but it is ajax, can anyone give me a hand setting it up please ?
( moved to javascript forum, i may have better luck )
thanks
http://www.petefreitag.com/item/605.cfm
http://script.aculo.us/downloads
Last edited by saltedm8; Apr 26th, 2008 at 15:34.
|
|
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|