criseltungala Posted July 13, 2010 Share Posted July 13, 2010 Hi. I'm having some issues with displaying the content of my database if I'm searching it with an array value on my PHP code. I am trying to create a code wherein the user will input 1 or multiple imperative sentences and then the program will divide it with the first set of delimiters and then after that, it will be subdivided again with the second set. After each word has been tokenized, I want to search for the word in my database and give its equivalent. For example: Hi. I'm having some issues with displaying the content of my database if I'm searching it with an array value on my PHP code. I am trying to create a code wherein the user will input 1 or multiple imperative sentences and then the program will divide it with the first set of delimiters and then after that, it will be subdivided again with the second set. After each word has been tokenized, I want to search for the word in my database and give its equivalent. For example: if my input string is "Hello! How are you? I'm fine thank you.", the results will be: Array [0] -> Hello! Array [1] -> How are you? I'm fine thank you. for Hello Array [0] -> Hello for How are you? I'm fine thank you. Array [0] -> How Array [1] -> are Array [2] -> you Array [3] -> I Array [4] -> m Array [5] -> fine Array [6] -> thank Array [7] -> you What i need to do is to compare each tokenized words into my database and give its equivalent word category like for the word "are" it will display "verb". I'm just new to php and I'm kinda lost already. Here's the copy of the code: <?php $con = mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("phrasal_lexicon_database", $con); if ($_POST['submit']) { $wordname_form = $_POST['wordname']; $delimiter="/[.!:;]/"; echo "Input string is <b>$wordname_form</b>. <br/>"; $token=preg_split($delimiter, "$wordname_form", -1, PREG_SPLIT_NO_EMPTY); echo "<br/> The splitted words are: <br />"; print_r($token); $counter =count($token); echo "<br/>The input string is divided into <b> $counter</b>.<br/>"; if (is_array($token)) { foreach ($token as $o) { $delimiter2="/[ ,.\/<>?;\\':\"\[\]\{\}\t\n\r~`!@#$%^&*()-=\\\_+|]/"; $token2=preg_split($delimiter2, $o, -1, PREG_SPLIT_NO_EMPTY); echo "<br/> The tokenized words from <b> $o </b> are: <br />"; print_r($token2); for($i = 0; $i < count($token); $i++) { foreach($token2 as $key=>$value) { $extract=mysql_query("select * from word_categories where id= '. $token2'"); $numrows=mysql_num_rows($extract); while ($row=mysql_fetch_assoc($extract)); { $wordnames=$row['word_name']; $wordcategory=$row['word_category']; echo "$wordcategory"; } } } } } else { echo"Failed"; } } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/207553-how-to-call-mysql-database-from-an-array-after-tokenizing-the-user-input-twice/ Share on other sites More sharing options...
ocpaul20 Posted July 14, 2010 Share Posted July 14, 2010 Too large a subject really. How do I do X? takes up too much time for most people to give you an answer. This seems to be a design problem as all these things should have been sorted out at design stage (analysis is what a systems analysts does!) If you have a specific code question, you may have more luck getting an answer. Link to comment https://forums.phpfreaks.com/topic/207553-how-to-call-mysql-database-from-an-array-after-tokenizing-the-user-input-twice/#findComment-1085677 Share on other sites More sharing options...
criseltungala Posted July 21, 2010 Author Share Posted July 21, 2010 Hi, I have finally figured it out . Here's what I have done <?php foreach ($token2 as $k=>$v) { $extract=mysql_query("SELECT * from word_properties where word_name='$v'"); while ($database_field=mysql_fetch_assoc($extract)) { echo "$v is "; print_r ($database_field['word_category']); echo "<br />"; } } ?> hope this code can help somebody who has the same issue. Link to comment https://forums.phpfreaks.com/topic/207553-how-to-call-mysql-database-from-an-array-after-tokenizing-the-user-input-twice/#findComment-1089286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.