Search Box to search mysql table fulltext php

Codes here !

Moderators: macek, egami, gesf

Post Reply
NigelRen
php-forum Fan User
php-forum Fan User
Posts: 622
Joined: Fri Aug 05, 2011 9:53 am

Re: Search Box to search mysql table fulltext php

Post by NigelRen » Fri Aug 17, 2012 11:35 pm

Have you tried running your SQL in something like phpmyadmin? This is just to make sure that your SQL is performing OK.

As for coding - you always seem to fetch a row - check what sort of information you have and then fetch the next row ( using mysql_fetch_array ) - this would mean that you will always miss the first row of data retrieved anyway.

NigelRen
php-forum Fan User
php-forum Fan User
Posts: 622
Joined: Fri Aug 05, 2011 9:53 am

Re: Search Box to search mysql table fulltext php

Post by NigelRen » Fri Aug 17, 2012 11:46 pm

One thing that could make your code a bit easier would be to let the SQL code do a bit more for you. So rather than having to work out which fields are set you could do something like...

Code: Select all

SELECT "Advert" as type, header, ad_text
    FROM advert 
    WHERE MATCH (header,ad_text) AGAINST ('$searchquery')) 
UNION 
SELECT "Business" as type, company as header, aboutus as ad_text
    FROM members 
    WHERE MATCH (company,aboutus) AGAINST ('$searchquery')
I haven't tested this but I hope you see the idea - it allows the SQL code to give you the same bits of information for each possibility, just with a label as to the sort of data it is.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests