473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

search help

can some one please help me adapt my script so that i can search for multiple words within my database,


my keywords feild looks something like this....
Expand|Select|Wrap|Line Numbers
  1. Big Teddie Bear Collection Tiny Small Soft
  2.  
At the moment if i search for the word "teddie" i will get "teddie" and if i search for "teddie bear" i will get "teddie bear", because in the keywords feild in the database "teddie" and "bear" are next to each other. but if i search for soft teddie i would get no results please help.

this is my script....

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4.  function search() {
  5.  
  6.   // Get the search variable from URL
  7.   $var = ucwords(strtolower(@$_GET['q']));
  8.   $trimmed = trim($var); //trim space from the stored variable
  9.  
  10. // rows to return
  11. $limit=15; 
  12.    $s = trim(@$_GET['s']);
  13.  
  14. // check for an empty string and display a message.
  15. if ($trimmed == "")
  16.   {
  17.  
  18.   }
  19.  
  20. mysql_connect("localhost","username","pass"); //(host, username, password)
  21.  
  22. mysql_select_db("myphotos") or die("Unable to select database"); //select which database we're using
  23.  
  24. // Build SQL Query           
  25. $query = "SELECT id, description, tn_src, src, lens, titles FROM dogs WHERE CONCAT(keywords, ' ', id, description, lens, camera, copyright, titles, Price) LIKE \"%$trimmed%\"
  26.   ORDER BY id DESC"; 
  27.  
  28.  $numresults=mysql_query($query);
  29.  $numrows=mysql_num_rows($numresults);
  30.  
  31. if ($numrows == 0)
  32.   {
  33.  
  34.   $q = "SELECT titles, description, tn_src, src, id FROM dogs ORDER BY RAND() LIMIT 15";  
  35.  
  36.   $r = mysql_query($q) or die("Couldn't execute query");       
  37.  
  38.  
Sep 23 '09 #1
18 2373
Markus
6,050 Expert 4TB
This articles should be of some help to you: http://devzone.zend.com/article/1304
Sep 23 '09 #2
I have read the articles and iv tryed many combinations but still cant work it out. I have never done a search script before and im finding it a bit difficult, can any 1 else help me out a bit more please.
Sep 23 '09 #3
dlite922
1,584 Expert 1GB
Forget the code and first work out your query from a command line or an SQL client interface.

Why doesn't your query get any results? Does it have an error? Do all the fields exist?

Why are you searching words in id, price, etc instead of just 'keyword' and 'description' fields?



Dan
Sep 23 '09 #4
I dont have any errors i have checked already, I am searching in all fields because all the photos require all that infomation to be called in, the search does work but only for 1 word or 2 that are together in the database.
Sep 23 '09 #5
Markus
6,050 Expert 4TB
Well, the article I provided covers the problem clearly, so I won't reiterate it. Also, see this page of the MySQL documentation.
Sep 23 '09 #6
I think im close but not sure wat im missing

Expand|Select|Wrap|Line Numbers
  1.  
  2. $query = "SELECT * MATCH(keywords, ' ', id, description, lens, camera, 
  3. copyright, titles, Price)AGAINST LIKE \"%$trimmed%\" FROM dogs WHERE
  4.  MATCH (keywords, ' ', id, description, lens, camera, copyright, titles, Price)
  5.  AGAINST LIKE \"%$trimmed%\" 
  6.   ORDER BY id DESC";
  7.  
  8.  
Sep 24 '09 #7
i get an error, says $numrows has an invalid argument,
Sep 25 '09 #8
Dormilich
8,658 Expert Mod 8TB
$numrows is a variable and variables typically don’t have input parameters.
Sep 25 '09 #9
sorry i ment this.........

Expand|Select|Wrap|Line Numbers
  1.  
  2. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gary/public_html/functions.php on line 35 
  3.  
  4.  
Sep 25 '09 #10
Dormilich
8,658 Expert Mod 8TB
that happens when you don't check for the mysql_query() execution success.
Sep 25 '09 #11
how do i go about doing that? it worked ok before i changed my $query
Sep 26 '09 #12
Dormilich
8,658 Expert Mod 8TB
basicly it goes like
Expand|Select|Wrap|Line Numbers
  1. mysql_query(…) or die(mysql_error());
Sep 26 '09 #13
Thanx i will defo be using that from now on. I get the error

MySQL server version for the right syntax to use near '' ', id, description, lens, camera, copyright, titles, Price) AGAINST LIKE ("' at line 1

this is my query im using......

Expand|Select|Wrap|Line Numbers
  1.  
  2. $query = "SELECT *, MATCH(keywords, ' ', id, description, lens, camera,  
  3. copyright, titles, Price) AGAINST LIKE (\"%$trimmed%\") FROM dogs WHERE 
  4.  MATCH (keywords, ' ', id, description, lens, camera, copyright, titles, Price) 
  5.  AGAINST LIKE (\"%$trimmed%\")  
  6.   ORDER BY id DESC";
  7.  
  8.  
Sep 26 '09 #14
Dormilich
8,658 Expert Mod 8TB
' ' (in MATCH()) is not a valid field.
Sep 26 '09 #15
thanx... but now got this

version for the right syntax to use near 'LIKE ("%Bear%") FROM dogs WHERE MATCH (keywords, id, description, lens, camer' at line 2
Sep 26 '09 #16
Dormilich
8,658 Expert Mod 8TB
@Markus
if you would have read that, you wouldn’t have to do trial and error.
Sep 26 '09 #17
Hi there,
Is there any readymade class available for searching keywords or any query form database if we assign field of table to class?
Oct 5 '09 #18
This site is amazing and I love it.
Oct 5 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: R. Rajesh Jeba Anbiah | last post by:
Q: Is PHP search engine friendly? Q: Will search engine spiders crawl my PHP pages? A: Spiders should crawl anything provided they're accessible. Since, nowadays most of the websites are been...
2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
2
by: Scott | last post by:
I'm trying to use the HTMLHelp API calls in a VB.NET program because I want a little more functionality than is offered by the Help class in .NET. Everything works fine except for displaying the...
3
by: Sheau Wei | last post by:
This is the search engine code that i create, but it was error and didnt come out the result. Cn u help me to check what wrong with my code? Thanks <Table cellspacing=1 cellPadding=1...
3
by: alaa123 | last post by:
hi plz do not ignore me I really neeed ur help I am working on a progarmme to implement First Search and Breadth Search I did the first search algorithm but I need help with implementing the...
0
by: xmanofsteel69 | last post by:
I'm trying to create a search function for my site and I can't ever seem to figure it out. If anybody could help, that would be awesome, because everything I try, I keep getting errors... Here's...
3
markmcgookin
by: markmcgookin | last post by:
Hi Folks, I have a VB app, and I have been working at it for a while, and I am now at the stage where I want to create a search function. Now don't be scared! It is in the .Net compact framework,...
0
by: kang jia | last post by:
hi currently i am doing this search function for car booking website. it can search through either car seats or CarModel. it seems it able to do search function, however i small problem occurs to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.