php链接中的参数/值

I got 2 .php pages:

  1. index.php : the main page with 4 pictures (1 by sensor)
  2. function.php : display temperature from a sensor and send it with the sensor id to a database

I want to click on the sensor's pic and be redirected to a display page (function.php).

In index.php, I will have probably:

< a href="funtion.php?1">pic1.jpg< /a>" <br>
< a href="funtion.php?2">pic2.jpg< /a>" <br>
< a href="funtion.php?3">pic3.jpg< /a>" <br>
< a href="funtion.php?4">pic4.jpg< /a>" <br>

In my function.php page, I want to store the number after ? as a variable ($id). In this page I will send the variable $id to collect the temperature, display id & temp and store id & temp to database.

My Question is: How can I collect the number in the url and store it in a variable?

in PHP this is simple.

I have the URL

<a href="function.php?myparameter=12345">Link here</a>

all I have to is the following (in the target page - function.php) to retrieve the named url URL parameter.

if (isset($_GET['myparameter'])) {
       $myVariableName =  $_GET['myparameter'];
}

Good luck!

You can use variables passed to the current script via the URL parameters with $_GET

Imagine you've a link like:

<a href="some_script.php?pic_number=1">pic1.jpg</a>

you can retrieve the pic_number value using:

<?php
if(isset( $_GET['pic_number']))
{
    $pic_number = $_GET['pic_number'];
    # do something with $pic_number
}