Current location: Hot Scripts Forums » Programming Languages » PHP » another php search mysql problem


another php search mysql problem

Reply
  #1 (permalink)  
Old 06-23-04, 08:41 AM
sumogray sumogray is offline
Newbie Coder
 
Join Date: May 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy another php search mysql problem

hi all, ive had this problem for a few days now and cant solve it, ive tried various searches but come up with nothing... im trying to search multiple fields with one search term (names and addresses) so if i have the following record:

name: bill gates
company: microsoft
street: 1 microsoft way
town: sometown
county: somecounty
postcode: lkfggj1

.. i can search for "gate" and the script would look through name, company, street, town, etc and if it found "gate" would display the full record... Im using the following script but i get no results no matter what search terms i use...

PHP Code:

<?


include ("includes/connect.php");
$getContent mysql_query("SELECT * FROM clients,contacts 
                            WHERE (clients.client_id = contacts.client_id) AND
                            company_name LIKE '%
$dosearch%' OR
                            company_name IS NULL OR
                            street LIKE '%
$dosearch%' OR
                            street IS NULL OR
                            town LIKE '%
$dosearch%' OR
                            town IS NULL OR
                            postcode LIKE '%
$dosearch%' OR
                            postcode IS NULL
                            "
) or
    die (
mysql_error());
    while (
$row mysql_fetch_array($getContent)){
        echo 
$row['contact_name'];
        echo 
"<br />";
        echo 
$row['company_name'];
        echo 
"<br />";
        echo 
$row['street'];
        echo 
"<br />";
        echo 
$row['town'];
        echo 
"<br />";
        echo 
$row['postcode'];
        echo 
"<br />";
        echo 
$row['contact_directline'];
        echo 
"<br />";
        echo 
$row['contact_mobile'];
        echo 
"<br /><br /><p>______________________________________________</p>";


?>
I'm setting $dosearch in the form using method="get"

thanks for any help!
gray
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-23-04, 10:22 AM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
See if this works:

PHP Code:

SELECT FROM clients,contacts WHERE (clients.client_id contacts.client_id) AND (contacts.company_name LIKE '%$dosearch%' OR contacts.street LIKE '%$dosearch%' OR contacts.town LIKE '%$dosearch%' OR contacts.postcode LIKE '%$dosearch%'
An alternative is to use MySQL's Full-Text Search Functions: http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-23-04, 11:20 AM
sumogray sumogray is offline
Newbie Coder
 
Join Date: May 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
ok cool thanks, ive converted to fulltext, and i think the problem must be something to do with the way im displaying the results, cos its still just a blank page.... cant see whats wrong though
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-24-04, 01:00 AM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Interesting... I can't see what's wrong with it either...

The pervious query I gave should work, and your output code looks ok.

Maybe if you posted some sample data (SQL dump) I could test it out for you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-24-04, 10:13 AM
sumogray sumogray is offline
Newbie Coder
 
Join Date: May 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
i think the problem lies in the fact im searching 2 seperate tables.. i changed the search to one table and got results.

is there anything to consider when doing fulltext searches on two tables?

thanks for your help!

'clients' holds company names and addresses
'contacts' holds peoples names and telephone numbers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-26-04, 02:54 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

So what does your SQL statement look like now? Are you using MATCH...AGAINST... or something else? How do you join two tables? I see you are using INNER JOIN, and in that case, are you aware that you will get no rows returned if the corresponding table does not have entries? (i.e. if clients table does not have related records in contacts table, it will not come up, even if it matches your search terms)

Thought it was an interesting question. If you already solved this, would you care to post what was wrong?

Cheers. =)
__________________
Blavv =|
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-28-04, 09:03 AM
sumogray sumogray is offline
Newbie Coder
 
Join Date: May 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
The only way i could figure to do it was to split the searches... so i now have 2 seperate searches, one by person one by company - i had to also resort back to LIKE statements, because i need to use wildcards, and i dont think you can using FULLTEXT

Code:
SELECT * FROM contacts WHERE (contact_name) LIKE ('%$keyword%') OR
							(department) LIKE ('%$keyword%') OR
							(job_title) LIKE ('%$keyword%')
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
How to create a php mysql site searchable from search engines? Klesti PHP 2 05-16-04 05:09 PM
Database table contents to email problem (PHP and MySQL) blokeofftheinternet PHP 2 04-29-04 10:34 AM
Problem with adding content to mysql from php HasansWeb PHP 3 01-10-04 06:26 PM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 07:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.