Helpful Information
 
 
Category: PHP Development
Passing variables with hyperlink

I've managed to get a MySQL database up and running and can display the data with PHP to a web page. What I'd really like to do is click on a field on the web page to display another page based on that value.

As an example using a membership database, I display an index of member no and member name to a web page. I'd like the member no to be a link that when clicked on would allow me to display the entire member record.

I just need to know how to pass the variable from the hyperlink to a php script to do the query.

TIA

What you have to do is put a ? on the end of your URL with varname=value after it.

For example
http://blah.blah.blah/script.php3?num=2
You can then access $num in your script, which will have a value of 2.

You can of course create this URL in your previous script with something like this

echo "<A HREF="script.php3?num=;
echo $row[0];
echo ">";
echo $row[0];
echo "</A>";

Hope This Helps
Brendan.

What you have to do is put a ? on the end of your URL with varname=value after it.

For example
http://blah.blah.blah/script.php3?num=2
You can then access $num in your script, which will have a value of 2.

You can of course create this URL in your previous script with something like this

echo "<A HREF="script.php3?num=;
echo $row[0];
echo ">";
echo $row[0];
echo "</A>";

Hope This Helps
Brendan.


Once you've created your link, you will have to access the "GET" array so you can query the database for the specific record.

for example your QUERY STRING (in the above example) "?num=x"... you would have to reference this as $_GET["num"] (naturally you can create parsing routines that simplify the reference to the passed name=value pair. like:



foreach($_GET as $key=>$value) {
Global $key;
$$key = $value;
}


you would then be able to reference $_GET["num"] as $num.

you would then query your table like SELECT * FROM table WHERE membertablerowid = $_GET["num"] --

Any way to get a variable from a URL like this... http://www.blah.com/293842
to pull that number out...
Or like these?

http://www.blah.com/?293842
http://www.blah.com/index.php?293842

Without putting a variable name in there like the previous stated examples?

If you don't want things showing, post it. If you don't know what these things are, I recommend you do some boning up before you deliver product.










privacy (GDPR)