Jump to content

Recommended Posts

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,

 

Link to comment
https://forums.phpfreaks.com/topic/206773-php-search-form/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081458
Share on other sites

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>";
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081512
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081724
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/206773-php-search-form/#findComment-1081763
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.