Hi there, I was hoping someone could help me with a little bit of code I'm currently writing, to explain what I'm trying to do -
The script I have written is a modification to Sam Broadcaster to allow for text requests via http on Oseki Server Manager.
Basically, a user will submit a text message - say - "Bon Jovi - Livin On A Prayer"
I was then using split to take it apart at the dash and query the database under artist/title. However, I'm attempting to write a suitable method that will allow me to allow for all instances , such as "Bon Jovi-Livin on a prayer" & "Bon Jovi- Livin on a prayer" You see the spacing changes? as I'm using WHERE ARTIST LIKE '%$artist%', effectively the whitespace is breaking it..
Really hope I'm making sense so far, I have a tendency to rant a little ! Have a look at my code...
PHP Code:
$data = $_GET["songname"]; // GET SONG NAME FROM GET STRING I.E LOCALHOST/REQ.PHP?SONGNAME=... echo "$data<br/><br/>"; // ECHO RAW DATA FOR TEST
$alldata = str_replace(" - ", "-", $data); // REPLACE - WITH 2 SPACES $alldata = str_replace("- ", "-", $data); // REPLACE - WITH 1 SPACE
echo "$alldata<br/><br/>"; // ECHO REPLACED DATA
list($artist, $title) = split('[-]', $alldata); // SPLIT REPLACED DATA echo "artist: \"$artist\"<br/>"; // ECHO ARTIST echo "title: \"$title\"<br/>"; // ECHO TITLE
$result = mysql_query("select * from songlist WHERE artist LIKE '%$artist%' AND title LIKE '%$title%' order by ID DESC LIMIT 0,1");
while($r=mysql_fetch_array($result))
{ $ID=$r["ID"]; // GET THE ID WHICH THEN SENDS TO SAM BROADCASTER }
Where I am effectively stuck is on the str_replace, I'm aware that by replacing an instance of a dash without a space, it's overwriting any other method... Is there something else I can do? Or certainly a mysql query that would allow for the whitespace on the beginning of the 'search' ?
Hope this makes sense, would really appreciate any help!
Cheers,
Andy
__________________
Please login or register to view this content. Registration is FREE - THE Harry Potter Resource!
Last edited by andypugh; 03-24-2009 at 08:50 PM..
|