Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 06-05-03
Andyc
Guest
 
Posts: n/a
  PHP Help


Hello,

I'm having touble searching mysql database It will search exact matches ie 'domain names' but if I type 'Domains and Hosting' it won't find anything. How do I get the search script to find anything that matches what the users has searched for.

I have included the script below.

Thanks

------
<?php

// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable

// rows to return
$limit=10;

// check for an empty string and display a message.
if ($trimmed == "")
{
echo "";
exit;
}

// check for a search parameter
if (!isset($var))
{
echo "

We dont seem to have a search parameter!</p>";
exit;
}

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("***********","***********","******* ****"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("***********") or die("Unable to select database"); //select which database we're using

// Build SQL Query
$query = "select * from comp4 where keywords like \"%$trimmed%\"
order by affiliate"; // EDIT HERE and specify your table and field names for the SQL query

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "

Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";

// google
echo "

<a href=\"http://www.google.co.uk/search?q="
. $trimmed . "\" target=\"_blank\" title=\"Look up
" . $trimmed . " on Google.co.uk\">Click here</a> to try the
search on google</p>";
}

// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}

// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "

You searched for: &quot;" . $var . "&quot;</p>";

// begin to show results set
echo "Results";
$count = 1 + $s ;

// now you can display the results returned
echo "<table width=\"100%\">";
echo "<table border=\"0\">";
echo "<tr>";
echo "<td width=\"\"></td>";
echo "<td width=\"\"></td>";
echo "</tr>";

while ($row= mysql_fetch_array($result)) {
$logo = $row["logo"];
$description = $row["description"];

echo "<tr>";
echo "<td width=\"100\" valign=\"top\">" . $logo . "</td>";
echo "<td width=\"\" class=\"font\">" . $description . "</td>";
echo "</tr>";
$count++ ;
}
echo "</table>";

$currPage = (($s/$limit) + 1);

//break before paging
echo "<br />";

// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt;
Prev 10</a>&nbsp&nbsp;";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

// not last page so give NEXT link
$news=$s+$limit;

echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
}

$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "

Showing results $b to $a of $numrows</p>";

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-06-03
ShowYouLoveThem
Guest
 
Posts: n/a
  Re: PHP Help


That script does a substring search, so if you seach for "domain" it will match with "domain names" or "name domains". If you search for "name" it will match with "domain names" or "name domains". If you search for "domain name" it will just match with "domain names".

Thats probably as clear as mud!

If you want more control when working with large amouts of text, have a look at using fulltext indexes. The latest version of MySql gives more control over seraches, using queries like "+domain -name" to include and exclude certain words, but I haven't had chance to work with that yet.

By the way, I do find the MySql & PHP online documentation quite easy to read and they both include users annotations at the bottom that can give a bit of insite.

Rich
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-06-03
scifind
Guest
 
Posts: n/a
  SQL Fix


You could:
=========PsudoCode=============
$query = "select * from comp4 where "
$search_term = explode(" ", $var); //may need reg experssion to explode by spaces and all punctuation

for each $search_term {

$query = $query.("keywords like \"%$search_term [$n]%\" OR");
}

//will need to do substring or similar to get rid of last OR


$query = $query.(" order by affiliate");

==============================

Sorry for the psudocode but i hope you get the idea
I havent got my php head on today
(copy paste King!)

PS can you list a comp for me
www.scifind.co.uk www.totaltelly.co.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-06-03
Andyc
Guest
 
Posts: n/a
  Re: PHP Help


Cheers for the help, still having problems though, new to PHP.

scifind - I would list a competition for you only my site is going to be an IT search engine!

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 07-06-03
scifind
Guest
 
Posts: n/a
  My Bad


Sorry I am easily confused, its the age you know, is ther a comp site comps 4 u or something?

Oh well -

What is the problem, is it the little bit of psudoscript?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-06-03
Andyc
Guest
 
Posts: n/a
  Re: PHP Help


Hello,

Yeah, I'm not to sure what 'psudoscript' is, I'm new to PHP, and I can't afford to spend all day learning, so any help you can give me is great.

Andrew
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-06-03
scifind
Guest
 
Posts: n/a
  Psudoscript


Sorry
Psudoscript is a made up term, the code I used was part real code and part instruction to the coder where I couldn't remember syntax or was just being lazy.

Who wrote the origional code?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 07-06-03
bertm
Guest
 
Posts: n/a
  Re: Psudoscript


<blockquote><strong><em>Quote:</em></strong><hr>
I'm new to PHP, and I can't afford to spend all day learning
[/quote]

maybe you shouldn't bother with it at all then?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-06-03
Andyc
Guest
 
Posts: n/a
  Re: PHP Help


bertm - If it wasn't so good and time saving I wouldn't!

Scifind - It was a free script I downloaded from www.designplace.org

Andrew
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Use vb.net or php to build product feed site? accelerator Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 2 18-01-05 03:32 PM
Anyone anygood with xml, php, mysql and Affiliate Window AnnonnyMouse The Affiliate Marketing Lounge 1 23-09-04 11:00 AM
Php & Sql Wunderlust1 Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 8 20-08-04 10:22 AM
PHP - No input file specified. - Problem Barry Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 1 02-08-04 10:57 AM
PHP or Browser Timeout? Barry Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 6 28-04-04 01:04 PM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7