beansandsausages Posted January 7, 2008 Share Posted January 7, 2008 hello all, i don't know if this sould be in here or the mysql help. But i am currently using a string replace script to change words in to faces ie : $words = array('', ':-)', ':^)'); $faces = array('<img src=images\emoticons\smile.gif />',); $message['msg'] = str_replace($words, $faces, $message['msg']); That works fine, i was just woundering is there a way to do this via database, so every time i wanna add a new face etc... i dont have to keep editing the page? Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/ Share on other sites More sharing options...
adam291086 Posted January 7, 2008 Share Posted January 7, 2008 I think it should possible. Have a table that stores all the words. Have another table with all the image loactions. Link the image to the words via the primary and forgine keys, Then all you need to do is query the database on the user input ~ . Then if the result == 1 then find out the image id and query the picture table so the scr and echo it out. Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432559 Share on other sites More sharing options...
Cazrin Posted January 7, 2008 Share Posted January 7, 2008 No need to have 2 tables to do it, just 1 table and 2 columns. Column 1 = smiley Column 2 = replace Build your 2 arrays based on each column, and then use the same code you've got already. Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432560 Share on other sites More sharing options...
adam291086 Posted January 7, 2008 Share Posted January 7, 2008 Yeah you can use one, better practice to have two, normalisation an all. It depends on how big the database will get. Also some words for a smailey face may be :-) :>) Therefore there could be hundreds of instances of the same image source. To change them may be a pain in the arse. At least with two tables he only has to change one item. Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432563 Share on other sites More sharing options...
beansandsausages Posted January 7, 2008 Author Share Posted January 7, 2008 so how would i code it, i have a db called faces, three tables with in it, ID, WORD and IMAGE, sumit like: select from db were $word = $input word haha i have no idea Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432564 Share on other sites More sharing options...
adam291086 Posted January 7, 2008 Share Posted January 7, 2008 Need a bit more detail. How are you getting $word? Is it in a text area? Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432566 Share on other sites More sharing options...
beansandsausages Posted January 7, 2008 Author Share Posted January 7, 2008 atm the only script it is used on is a update script the message is in the db ie : message : hiya then when its pulled out the db it goes throught the string replace and comes out as : Hiya . but every time i add a new one dont wanna edit the file so tohught might be easier to keep them in the db Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432567 Share on other sites More sharing options...
adam291086 Posted January 7, 2008 Share Posted January 7, 2008 ok so when you pull hiya "" out of your database you need to split the string up, One into text and the other into the image. Once you have done that you can query the databse with you new variable. Then the result return can be set to a variable as well. Then set your img source to the query result variable. This is very dependent on your image being in the same location every time. Use this php function to seperate the words http://uk3.php.net/manual/en/function.explode.php Quote Link to comment https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.