Current location: Hot Scripts Forums » Programming Languages » PHP » Php GET function problem


Php GET function problem

Reply
  #11 (permalink)  
Old 04-11-11, 10:41 AM
yazz_1988 yazz_1988 is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Hi sorry to be so late on the follow up questions, i have a couple of things i'd like to ask

why do we need the # sign in the action, what does it do? i see it shows up in the url after i hit enter, but i'm not sure as to why we use it.

Another thing; as it stands the text input gets cleared up since the page reloads, is there any way to maintain the text input past the refresh, i ask this because i want to add another query linked to a button on the frontpage, that will show route a -> route b and route b -> route a, and i would need to $input for the query to work and not have user input it again.

oh and by the way that above solution does work, thanks for that.
Reply With Quote
  #12 (permalink)  
Old 04-12-11, 12:17 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by yazz_1988 View Post
Hi sorry to be so late on the follow up questions, i have a couple of things i'd like to ask

why do we need the # sign in the action, what does it do? i see it shows up in the url after i hit enter, but i'm not sure as to why we use it.

Another thing; as it stands the text input gets cleared up since the page reloads, is there any way to maintain the text input past the refresh, i ask this because i want to add another query linked to a button on the frontpage, that will show route a -> route b and route b -> route a, and i would need to $input for the query to work and not have user input it again.

oh and by the way that above solution does work, thanks for that.
To answer your first question: The # sign used in the forms action property is there to make the form submit back to the page it is contained in, or in other words, submit back to itself.
If you don't want the # sign to show up in the URL then change the action property to the name of the file that the form is contained in.

To answer your second question: If you want the value that is entered into the text input element to be there after the page is reloaded then you must reload the value back into the input element.
Something like this:
PHP Code:

Type route number: <input name="input" type="text" value="<?php echo $_POST["input"] = empty($_POST["input"]) ? "" $_POST["input"]; ?>" />
This should fix your problem.

Note: I don't really want to rewrite your code, but I think if you re-evaluate the way you are using your form, then you should see a way to use it without submitting it by using the onsubmit event listener.

I can't help notice that every time the page reloads it executes the initialize() function.
You could use the forms onsubmit event listener to run a function that would execute the initialize() function without submitting the form.
Then you could also use the same function to execute other tasks as needed.

Just a thought.
__________________
Jerry Broughton
Reply With Quote
  #13 (permalink)  
Old 04-14-11, 02:30 PM
yazz_1988 yazz_1988 is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Can u give me a link or two on how that is achieved? i'm not quite sure how to go about doing that.
I'm trying to make 2 buttons that would execute the following queries but not having much success with it

Code:
$query = "SELECT * FROM mydata WHERE routenumber = '$input' AND routerun =1";

$query = "SELECT * FROM mydata WHERE routenumber = '$input' AND routerun =2";
Reply With Quote
  #14 (permalink)  
Old 04-14-11, 06:14 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by yazz_1988 View Post
Can u give me a link or two on how that is achieved? i'm not quite sure how to go about doing that.
I'm trying to make 2 buttons that would execute the following queries but not having much success with it

Code:
$query = "SELECT * FROM mydata WHERE routenumber = '$input' AND routerun =1";

$query = "SELECT * FROM mydata WHERE routenumber = '$input' AND routerun =2";
In your HTML you could add a select element for routerun.
HTML Code:
<tr>
        <td colspan="2">
        Type route number: <input name="input" type="text"/>
      <input type="submit" value="Search!"><br />
        <select name="routerun">
        <option value="">...Select routerun...</option>
        <option value="1">1</option>
        <option value="2">2</option>
        </select>
        </td>
        </tr>
And then in your PHP modify this part:
PHP Code:

if(!empty($_GET['input'])){
    
$input $_GET['input'];
    
$routerun = empty($_GET['routerun']) ? "" "AND routerun ='"$_GET['routerun']."'";

And then modify your query:
PHP Code:

$query "SELECT * FROM mydata WHERE routenumber = '$input$routerun"
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks

Tags
javascript, php, xml


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Javascript in a php page binarybird PHP 1 06-21-10 05:57 AM
PHP Search Feature Problem jilawatan PHP 2 08-13-09 08:21 AM
Problem with CSS and PHP working together:( cssgopher PHP 7 03-24-08 03:31 AM
php function installation from php.net?? DangerZone PHP 5 11-09-07 10:28 PM
Urgent problem with PHP domxml_open_mem(), php extension php_domxml.dll. Need help! Oskare100 Web Servers 3 01-03-07 05:08 AM


All times are GMT -5. The time now is 08:46 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.