Jump to content

Help With Schema


paulmo

Recommended Posts

My app matches user submitted form message words to arrays, for matches on any word. Upon match, I echo a personalized response. I want to expand the app, so if $word matches the "good" array, for example

 (elseif (in_array(strtolower ($word), array('great', 'good', 'wonderful'))))

, then $word will get matched to a series of "keyword" arrays (sports, nature, family, etc.). Upon a match there, echo response to user, "Nature is a source of happiness for you" (for example). As the code is now, I just echo a response upon "good" array match.Someone suggested a database solution, of "scoring" array matches; for example, match on "good" array might be assigned 3, and keyword array set "family" might be 7, totaling 10, which would correspond to the "10" response: "You are happy about your family." However, JSG on this board helped me with first part of this app, which is all on PHP page, no database (except I insert original messages and words in tables). So I might want to keep doing this in application page, unless I get more advice to the contrary. I am seeing "nested elseifs" if that is a good option. Thanks in advance for ideas.

Link to comment
Share on other sites

Using a database or something may indeed be a more efficient and easy to expand way.The solution to your current problem is indeed one more condition within this one, but if you later decide to add more logic, it will likely end up as being one veeeery large and heavy app.

Link to comment
Share on other sites

Thanks...so in database, I'm guessing I will match message words (currently regex'ed; explode was not searching every word in message array) against `mood` columns holding current array words (good, great, etc); upon a matching row, message words will match against `subject` column (or columns?); a matching row there will correspond to a row in column `responses` which will hold response to echo to user? I'd like to do this all in one table. So the path would go: user string to regexed array (in app); query $words against `mood`, match there (good, for example) corresponds to `good subject` column; match there corresponds to `good subject response` column? Is my thinking OK here or is there a better way--numerical scoring system, etc? Would I need to put the user message or split message in its own db field first, and use that to search against `mood` and `keyword`, or can I do the query using $word variable in app?Regarding just adding another condition in app, could you please show me how in relation to existing elseif statement? Thanks.

Link to comment
Share on other sites

I can't help with the DB thing... I've never tried to create a similar app myself.As for creating another condition... something like this maybe:

$keywords = array('good' => array('sports', 'nature', 'family'),'wonderful' => array()//etc.);//etc.elseif (in_array(strtolower ($word), array('great', 'good', 'wonderful')))) {  if (isset($keywords[$word]) {	//Maybe add some more logic here	echo 'Nature is a source of happiness for you';  }}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...