BrendanmPHP Posted December 9, 2010 Share Posted December 9, 2010 I have a textarea feild in my form where the user can type in several keywords such as Textarea Box Below Cars Trains Buses I have a database with the meanings of the words entered and want to be able to get the three definitions from the database on for submission. In a normal input box where i only type one word i can grab no problem like so $word = $_POST['word']; $sql = "SELECT meaning FROM table WHERE word='$word'"; Though i am trying to get multiple values from the same textarea box So if a user types in 3 words the query would query the database on thoses three words, the problem is i dont know how to get the diffrent words from the form for example $first = $_POST['word']; which would be the first word $sec = $_POST['word']; which would be the second word etc. Any help here would be great thanks. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 9, 2010 Share Posted December 9, 2010 explode Quote Link to comment Share on other sites More sharing options...
BrendanmPHP Posted December 9, 2010 Author Share Posted December 9, 2010 I tried this if ($_POST['submit']){ $text = $_POST['ta']; $words = explode(" ", $text); echo $words[0]; } Though that still outputs all the words instead of word 1 or echo $words[1]; Still echos all the words instead of the 2nd word. EDIT i changed the explode to $words = explode(".", $text); and seperated my words with a . which works great Though how would i query all the words at once to return the 3 seperate meaning? I can do where word=$word1 AND $word2 etc Because sometimes there will be more words entered than other times. Quote Link to comment Share on other sites More sharing options...
BrendanmPHP Posted December 9, 2010 Author Share Posted December 9, 2010 I can do where word=$word1 AND $word2 etc Was meant to be "i cant" Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 10, 2010 Share Posted December 10, 2010 Try this query string (changed to your particular needs, obviously) $query = "SELECT `field1`, `field2`, `field3` FROM `table` WHERE `some_field` IN(" . implode( ',', $words) . ")"; Quote Link to comment 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.