PHP meeting search conditions -
i'm @ php entry level don't understand how it.
this website short story submission page
first have search.php page allows users search story records using multiple conditions such content contains have this: storysearch.php
<table border="1"> <tr> <td>include: <select name="optioncontent"> <option value="yes">yes</option> <option value="no">no</option> </select> </td> <td>story content contains: <input type="text" name="contains" /></td> </tr> <tr> <td>include: <select name="optionnum"> <option value="yes">yes</option> <option value="no">no</option> </select> </td> <td> number of words:<b> </b> <input type="text" name="minword" style="width: 25px;"><b> </b> <input type="text" name="maxword" style="width: 25px;" /> </td> </tr> </table> <input type='submit' value='submit' />
and ....submit cut out codes
the problem in page posted to, dostorysearch.php
if each include option yes, need include search condition database. if , else statement seem way have no idea how. got dostorysearch.php
<?php $checkcontent = $_post['optioncontent']; $checknum = $_post['optionnum']; if ($checkcontent == 'yes') { $content = $_post['contains']; echo $content; } else if( $checknum == 'yes') { $nums = $_post['minword']; $nume = $_post['maxword']; echo $nums."and". $nume; }
i don't understand how after part.whether ifelse or else?. appreciated! in advance!
there hundred ways it.
i'd work booleans, if there's still repetition, avoids of it:
$checkcontent = $_post['optioncontent'] == 'yes'; $checknum = $_post['optionnum'] == 'yes'; if ($checkcontent && $checknum) { // both } else if ($checkcontent) { // content } else if ($checknum) { // numbers } else { // error checking }
is clear enough ? booleans may not intuitive @ first, once understood, make code clear , readable.
if plan using sql, remember sanitize inputs.
Comments
Post a Comment