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.... -
Big Teddie Bear Collection Tiny Small Soft
-
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.... -
-
<?php
-
-
function search() {
-
-
// Get the search variable from URL
-
$var = ucwords(strtolower(@$_GET['q']));
-
$trimmed = trim($var); //trim space from the stored variable
-
-
// rows to return
-
$limit=15;
-
$s = trim(@$_GET['s']);
-
-
// check for an empty string and display a message.
-
if ($trimmed == "")
-
{
-
-
}
-
-
mysql_connect("localhost","username","pass"); //(host, username, password)
-
-
mysql_select_db("myphotos") or die("Unable to select database"); //select which database we're using
-
-
// Build SQL Query
-
$query = "SELECT id, description, tn_src, src, lens, titles FROM dogs WHERE CONCAT(keywords, ' ', id, description, lens, camera, copyright, titles, Price) LIKE \"%$trimmed%\"
-
ORDER BY id DESC";
-
-
$numresults=mysql_query($query);
-
$numrows=mysql_num_rows($numresults);
-
-
if ($numrows == 0)
-
{
-
-
$q = "SELECT titles, description, tn_src, src, id FROM dogs ORDER BY RAND() LIMIT 15";
-
-
$r = mysql_query($q) or die("Couldn't execute query");
-
-
18 2373
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.
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
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.
I think im close but not sure wat im missing -
-
$query = "SELECT * MATCH(keywords, ' ', id, description, lens, camera,
-
copyright, titles, Price)AGAINST LIKE \"%$trimmed%\" FROM dogs WHERE
-
MATCH (keywords, ' ', id, description, lens, camera, copyright, titles, Price)
-
AGAINST LIKE \"%$trimmed%\"
-
ORDER BY id DESC";
-
-
i get an error, says $numrows has an invalid argument,
$numrows is a variable and variables typically don’t have input parameters.
sorry i ment this......... -
-
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gary/public_html/functions.php on line 35
-
-
that happens when you don't check for the mysql_query() execution success.
how do i go about doing that? it worked ok before i changed my $query
basicly it goes like - mysql_query(…) or die(mysql_error());
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...... -
-
$query = "SELECT *, MATCH(keywords, ' ', id, description, lens, camera,
-
copyright, titles, Price) AGAINST LIKE (\"%$trimmed%\") FROM dogs WHERE
-
MATCH (keywords, ' ', id, description, lens, camera, copyright, titles, Price)
-
AGAINST LIKE (\"%$trimmed%\")
-
ORDER BY id DESC";
-
-
' ' (in MATCH()) is not a valid field.
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
@Markus
if you would have read that, you wouldn’t have to do trial and error.
Hi there,
Is there any readymade class available for searching keywords or any query form database if we assign field of table to class?
This site is amazing and I love it.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |