How would I search a result between certain characters

Hello, I have a music website and users can add songs to my database with song information.

Example: The Lazy Song (Happy Hotdog Remix)

mysql_query(“SELECT * FROM music WHERE musictitle=‘search between ( and )’”);

I would like to know how I would search the string for just the characters inside the brackets, I would like to add a “More remix’s by Happy Hotdog”, Although I can’t use use the term LIKE because it fetches the other results by the same title, I just want the songs with that particular remix?

Any help :O?

Never used this before but look up the ‘explode’ command… it separates a string at a certain character and inputs the parts into an array…

Hope that helps!

http://us2.php.net/manual/en/function.explode.php

have you tried using MATCH, AGAINST you can search for multiple words as long as there bigger then 3 characters

usage example:
[php]$sql = “SELECT * FROM articles WHERE MATCH(articlesTitle) AGAINST(’$search*’ IN BOOLEAN MODE)”;[/php]

Here’s a tutorial on using match against http://www.daveismyname.co.uk/tp-searching-with-php-and-mysql-beyond-like

SELECT * FROM `music` WHERE `musictitle` REGEXP '/\(Happy Hotdog Remix\)/i'

Thanks for the answers guys but I don’t think I explained properly, I was tired when I wrote that post…

When a user is viewing a song (Example: The Lazy Song (Happy Hotdog Remix)) I want to make it so I can search other songs in my database with the same remix so its like searching the database for the data between the current songs brackets in the database.

@daveismyname

I tried your method but got “The used table type doesn’t support FULLTEXT indexes”.

@Smokey PHP, how would I get the text in REGEXP from the current title?

@brentb, I tried your method also but the array parts arn’t always the same so I can’t really do it that way, I did think of this first but because there is more words in some titles I can’t always use the same array number.

I manage to come up with this but its returning either 1 or no results…

[php] $GetRemix = $_GET[‘title’]; //Marry You (Happy Hotdog Remix)
$RemixName = explode(’(’, $GetRemix);
print_r($RemixName);

$remix1 = $RemixName[1]; //Happy Hotdog Remix)

$get2 = mysql_query("SELECT * FROM `music` WHERE `musictitle` LIKE '%".$remix1."%%'") or die(mysql_error());

while($rem = mysql_fetch_array($get2));
{

	echo $rem['musictitle'];

}[/php]

?? :o, If I do the same in mysql query browser it fetches results but it don’t work in PHP?

Sorry for triple posting but I figured it out! I put a ; on the end of the while statement :0! thanks for the replys everyone but thanks especially to brentb! I managed to do 2 explodes to remove the other ending bracket and it now works perfect! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service