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. Link to comment https://forums.phpfreaks.com/topic/221150-get-multiple-form-values-from-one-input-box/ Share on other sites More sharing options...
Pikachu2000 Posted December 9, 2010 Share Posted December 9, 2010 explode Link to comment https://forums.phpfreaks.com/topic/221150-get-multiple-form-values-from-one-input-box/#findComment-1145080 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. Link to comment https://forums.phpfreaks.com/topic/221150-get-multiple-form-values-from-one-input-box/#findComment-1145091 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" Link to comment https://forums.phpfreaks.com/topic/221150-get-multiple-form-values-from-one-input-box/#findComment-1145100 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) . ")"; Link to comment https://forums.phpfreaks.com/topic/221150-get-multiple-form-values-from-one-input-box/#findComment-1145214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.