rajthampi Posted July 5, 2010 Share Posted July 5, 2010 Hi guys This is my first post here and I am a beginner with PHP. I am trying to build a php mysql search page. The search parameters are many (text boxes and checkboxes) on submit the page call itself to execute the search. Now I am stuck with one issue. As soon as the user submits the form, all the text boxes and checkboxes get cleared (normal behavior) and fetches the results after clearing the form, leaving the user in a wild guess what was been entered into the text columns as well which were the checkboxes select prior submission. Is there any work arounds to deal with this situation? I mean I don't want the form field elements to be cleared. I tried to retrieve the values from $_POST and assign to the text boxes, however running out of clues with checking the checkboxes. Please help regards, Quote Link to comment https://forums.phpfreaks.com/topic/206773-php-search-form/ Share on other sites More sharing options...
harristweed Posted July 5, 2010 Share Posted July 5, 2010 <input type="checkbox" value=" yes" name="checkbox" <?php if($_POST['checkbox']=="yes")echo " checked = \"checked\" ";?> > Quote Link to comment https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081334 Share on other sites More sharing options...
rajthampi Posted July 5, 2010 Author Share Posted July 5, 2010 My checkboxes are dynamically written as below: <?php $query="select column_name fldnm, column_comment fldcomment from information_schema.columns where table_name='burial_listing' and column_name not in ('dod','id')"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "<input type=\"checkbox\" name=\"items[]\" value = \"".$row["fldnm"]."\">".$row["fldcomment"]."<br>"; } ?> btw thank you very much for the post. Quote Link to comment https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081458 Share on other sites More sharing options...
jcbones Posted July 5, 2010 Share Posted July 5, 2010 Try using in_array() <?php $query="select column_name fldnm, column_comment fldcomment from information_schema.columns where table_name='burial_listing' and column_name not in ('dod','id')"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $checked = (isset($_POST['items']) && in_array($row['fldnm'],$_POST['items'])) ? ' checked="checked"' : NULL; echo '<input type="checkbox" name="items[]" value = "'.$row["fldnm"].'" ' . $checked . '>'.$row["fldcomment"]."<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081512 Share on other sites More sharing options...
rajthampi Posted July 6, 2010 Author Share Posted July 6, 2010 Thank you jcbones. I am yet to get back at work. I will try the code and post my comments. regards, Quote Link to comment https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081718 Share on other sites More sharing options...
StefanRSA Posted July 6, 2010 Share Posted July 6, 2010 PLEASE PLEASE also take note... I also struggle a lot building a search. Eventually after getting the search to do what I want I ran into a new problem... SLOW searches.... Sometimes a search query can take up to 40sec if the columns you are searching are not indexed in your DB... So... VERY IMPORTANT and I hope I could help! Index every column in the DB that you want to search! Quote Link to comment https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081724 Share on other sites More sharing options...
rajthampi Posted July 6, 2010 Author Share Posted July 6, 2010 Thanks Stefan for your input. Slowly I am getting convinced about using Ajax to deal with this situation. I found some nice tutorials and examples and planning to migrate into an Ajax based solution which will save me loads of time. Thank you guys. One more question. How do I mark this thread as solved? Quote Link to comment https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081763 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.