Forum Moderators: coopster

Message Too Old, No Replies

Trying to send variables via URL using the same PHP script

         

BigRedEO

6:55 pm on May 2, 2008 (gmt 0)

10+ Year Member



I have a PHP script which allows the user to type in either a store number or a serial number of a piece of equipment, then hit a Submit (form POST) button. If they choose store number, a page is returned with a list of equipment at this store along with their serial numbers. If a serial number is entered, it returns all stores where this piece of equipment has been.

I need to have the numbers returned as links which can be clicked on to return the same report for that number. For example, I enter store 1000 and get a list of equipment currently at that store. Each serial number in that list is a link, and I want to be able to click on a serial number and get the report back that lists where it's been - and vice versa. I'm not sure how to send back the number that is clicked as a variable to that same script - I'm assuming it would use GET in someway, but I'm not sure how.

Any help?

mustikos

8:29 pm on May 2, 2008 (gmt 0)

10+ Year Member



I am not 100% on what u are looking for... you can change all the $_POST in the form to $_GET, however, and the information is passed thru the url..

d40sithui

9:08 pm on May 2, 2008 (gmt 0)

10+ Year Member



ok, so you want the same page to be able to query for store number AND serial number. as mustikos mentioned you'd want to use GET.

lets say you have these links. one for the store number and the second for the serial number.


<!-- store link -->
<a href="myPage.php?storeNumber=1000">Store 1000</a>

<!-- serial link -->
<a href="myPage.php?serialNumber=9999">Serial 9999</a>

now on your script, you'd have to retrieve those values that were passed. you need to process for both because you never know if you're going to get the serial number or the store number. so, you have to check for both variables.


<?
//if store number is set
if(isset($_GET['storeNumber'])){
//retrieve store number and query accordingly
}

//if serial number was set
elseif(isset($_GET['serialNumber'])){
//retrieve serial number and process accordingly.
}

//none was set, default
else{

}
?>

BigRedEO

12:03 pm on May 6, 2008 (gmt 0)

10+ Year Member



Thank you. I was having trouble figuring out how to start with a POST to get the initial variables from the user, but then allowing them to click on links within the report they generate for further reporting.