Jump to content

Recommended Posts

hi all i can easly search 2 fields but for a learning experince and a more accurate search im going to split my search query with preg split so if i was searching for

"b52's love shack"

it becomes

$search[0]->b52's

$search[1]->love

$search[2]->shack

 

now the problem is "b52's" is artist and "love shack" is song

so i do this

SELECT * FROM songlist WHERE artist like '%$search[0]%' and artist like '%$search[1]%' and artist like '%$search[2' OR song like '%$search[0]%' and song like '%$search[1]%' and song like '%$search[2]%' ORDER BY artist

 

 

it returns no results any ideas ?

 

thank you for your time

Link to comment
https://forums.phpfreaks.com/topic/182717-search-2-fields/
Share on other sites

sorry 

i think the sql verion is MySQL client version: 4.1.22

i have tried this

mysql_query("SELECT * FROM songlist WHERE artist like '%$quicksearch%' OR song like '%$quicksearch%' ORDER BY artist");

and this

mysql_query("SELECT * FROM songlist WHERE * like '%$quicksearch%' ORDER BY artist");

data types are just tinytext

i havent bothered with preg split yet because it returns "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result"

 

does this help ?

Link to comment
https://forums.phpfreaks.com/topic/182717-search-2-fields/#findComment-965837
Share on other sites

this would be the query that doesnt work but its the best way to explain what im trying to do

mysql_query("SELECT * FROM songlist WHERE * like '%$quicksearch%' ORDER BY artist");

but if that had worked then i would have been able to do this

mysql_query("SELECT * FROM songlist WHERE * like '%$quicksearch[0]%' AND * like '%$quicksearch[1]%' AND * like '%$quicksearch[2]%' ORDER BY artist");

i dont know how else to explain just say if there was 3 key words it would check

if word 1 is in artist or song

and if word 2 is in artist or song

and if word 3 is in artist or song

 

then display the song i can search 1 word or 1 phrase in the same order as the list by

mysql_query("SELECT * FROM songlist WHERE artist like '%$quicksearch%' OR song like '%$quicksearch%' ORDER BY artist");

but the problem is if the first word was from the artisit and the second word was from the song it would not work.

i realy cant think of any other ways to explain i hope it helps like i said it was just for learing perposes its not important but i would enjoy knowing the answer.

thanx for your help so far :shy:

 

Link to comment
https://forums.phpfreaks.com/topic/182717-search-2-fields/#findComment-967385
Share on other sites

Why not:

 

SELECT * FROM songlist

WHERE

artist like '%$quicksearch[0]%' OR artist like '%$quicksearch[1]%' OR artist like '%$quicksearch[2]%'

OR song like '%$quicksearch[0]%' OR song like '%$quicksearch[1]%' OR song like '%$quicksearch[2]%'

ORDER BY artist

 

Not that it's going to be particularly efficient.

Link to comment
https://forums.phpfreaks.com/topic/182717-search-2-fields/#findComment-967472
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.