943,948 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 14857
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 7th, 2009
0

php code to search and show results on same page

Expand Post »
I have a names database with only 4 fields (Sex, Origin, Meaning, Starts With) and html search form for those same 4 fields. Can anyone give me the php code so that if anyone fills in any or all of the form fields, the results from the database will be produced on the same page as the search form.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpNewbie is offline Offline
13 posts
since Jan 2009
Jan 7th, 2009
0

Re: php code to search and show results on same page

Hi, you can have php code
php Syntax (Toggle Plain Text)
  1. <?php echo $_SERVER['PHP_SELF'];?>
on your form action to return the results in the same page.

and in the top of your page(the same page with the form), add conditional statements for all/any or search form fields and then query them ..

Show us your code for us to debug it.
Reputation Points: 11
Solved Threads: 2
Light Poster
enim213 is offline Offline
40 posts
since Jun 2008
Jan 7th, 2009
0

Re: php code to search and show results on same page

hi and thanks for your reply. I have no code (embarrassed) and was hoping someone could give me example with only 4 fields to query. I have no idea about php. I know how to make html form and i have .sql file to import to database but that is all. I dont know how to write the php code to make it all happen. I am making searches for scripts to play with but they are very confusing for me. I would very much appreciate any help you can give.
kind regards
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpNewbie is offline Offline
13 posts
since Jan 2009
Jan 8th, 2009
0

Re: php code to search and show results on same page

with that... try to search tutorials on google.. try website like w3schools.com, tizag.com.. there are many examples there.. including php and mysql for your data fetching.. when your done, post it quick here for us to know..

Actually its simple.. but we want something even a little effort.. that would really help you.
Reputation Points: 11
Solved Threads: 2
Light Poster
enim213 is offline Offline
40 posts
since Jun 2008
Jan 8th, 2009
0

Re: php code to search and show results on same page

php Syntax (Toggle Plain Text)
  1. <form action='<?php echo $_SERVER['PHP_Self']; ?>'>
  2. <input type='text' name='field1' value='<?php if(isset($field1)){echo $field1; } ?>'>
  3. <input type='text' name='field2' value='<?php if(isset($field2)){echo $field2; } ?>'>
  4. <input type='text' name='field3' value='<?php if(isset($field3)){echo $field3; } ?>'>
  5. <input type='text' name='field4' value='<?php if(isset($field4)){echo $field4; } ?>'>
  6. <input type='submit' onclick="return confirm('Are all fields complete?')">

I like to add confirmation to the submit button, degrades ok with javascript disabled,
Last edited by peter_budo; Jan 9th, 2009 at 6:13 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Jan 8th, 2009
0

Re: php code to search and show results on same page

Hi and thanks
I will try this too and let you know how it goes
regards
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpNewbie is offline Offline
13 posts
since Jan 2009
Jan 8th, 2009
0

Re: php code to search and show results on same page

Logial Correction, and statement of the obvious
php Syntax (Toggle Plain Text)
  1. <?php
  2. /*
  3. logical construct depends on your data,,,
  4. validate data entries,
  5. if valid
  6.  insert to mysql,
  7.  disable submit so data will not be aded to table twice,
  8.  or redirect to another page
  9. else
  10.  echo feedback to user to explain what is right/wrong with the submitted data before the form is resubmitted
  11. */ ?>
  12. <form action='<?php iecho $_SERVER['PHP_Self']; ?>'>
  13. <input type='text' name='field1' value='<?php if(isset($field1)){echo $field1; } ?>'>
  14. <input type='text' name='field2' value='<?php if(isset($field2)){echo $field2; } ?>'>
  15. <input type='text' name='field3' value='<?php if(isset($field3)){echo $field3; } ?>'>
  16. <input type='text' name='field4' value='<?php if(isset($field4)){echo $field4; } ?>'>
  17. <input type='submit' onclick="return confirm('Are all fields complete?')">
Last edited by almostbob; Jan 8th, 2009 at 11:50 pm.
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Jan 9th, 2009
0

Re: php code to search and show results on same page

Well now my go.

I have done something very very similar.

No you cannot have the code. It is MUCH MORE FUN it you work it out for your self.

For a start something that the previous posters forgot, what happens if more than one matching row is found (i.e. only the 'Sex' field was filled in?

The previous examples show HTML forms being used. I would suggest that you look at text boxes and handle the input / display using javascript and good old (new?) AJAX. Remember fields do not have to exist when the page is first displayed on the client screen. the DOM allows you to create objects, and set their values and all other properties on the fly.

QUICK TIP use different text areas for user input and data display, when the user submits some data expect it to be partial data and leave the focus in the same fiedl that the user last used. If the user submits "Pat" and you list out all of the Pat's / Patricia's & Partick's that you can find, the user will find it much easier to go on to finish Patraig.

I would recommend you get 'THE JAVASCRIPT BIBLE'. It contains a huge amount of information and will guide you through your first steps in implementing this type of function.
Reputation Points: 33
Solved Threads: 9
Junior Poster
pclfw is offline Offline
132 posts
since Jun 2005
Jan 9th, 2009
0

Re: php code to search and show results on same page

Hi thanks for your reply but you may as well have written it in arabic for all my understanding lol.

Allow me to explain - i'm absolutely new to php - had never even seen it before now beginning to research - i'm completely self taught html and some database and so what you have said makes no sense to me whatsoever. me being blonde doesn't help either lol so i wanna keep it very simple. I'm sure it would be a lot of fun to work it out myself but i work full time (not in IT) and have three kids so thats gonna take quite a while. I think my best bet is to just work through tutorial after tutorial, however long it takes - unless you wanna sell me your code lol - kidding

Thank you all for trying to help but i fear its just way over my head for now and maybe i should find another less confusing project to take up my 'spare' time (like naughts and crosses lol) - unfortunately i just don't 'get it'
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpNewbie is offline Offline
13 posts
since Jan 2009
Jan 9th, 2009
0

Re: php code to search and show results on same page

.. hey phpNewbie.. umm the sites i gave was a great help.. i am also a self taught coder.. i only search , read forums.. and it gave so much more than i think of..

it's easy to paste the code here but you have to learn it a step in a time..

goodluck, willing to give u code that can help
Reputation Points: 11
Solved Threads: 2
Light Poster
enim213 is offline Offline
40 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: mysql to pdf convert
Next Thread in PHP Forum Timeline: about web hosting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC