问题
I have 2 variables to send records.php, '$id' and '$row[0]". After it, I want to use them in newrecords.php with $_Get method.
Here 's index.php
echo '<td align="center">'.$row[0].'-) <a href="newrecords.php?mid=&id=' . $id . $row[0] . '"$ >'. $row[3] . " " . $row[4] .'</a></td>';
There's something going wrong.I see this url "newrecords.php?mid=&id=44" i want to see like this "mid=4&id=4" and after this
newrecords.php
if (isset($_GET['mid']))
{
$id = $_GET['mid'];
}
if (isset($_GET['id']))
{
$nid = $_GET['id'];
}
Is it right way to get them?
回答1:
You URL is malformed. You have to separate each key/value with a &. And better use & if it's in HTML.
echo('<td align="center">'.$row[0].'-) <a href="newrecords.php?id='.
$id.'&mid='.$row[0].'"$ >'.$row[3]." ".$row[4].'</a></td>');
So the structure is ?key1=value1&key2=value2&key3=value3
That way you can get them with $_GET['key1'] and $_GET['key2'] and $_GET['key3'].
The way you get them, you are using isset, that's tricky because they might be set but have no value. You can also use empty() for that. It actually checks whether a value is not 0 or empty. So if you don't use 0 as a record id you can better use that. And I also if they are id's I would cast them (making sure they are integers)
$id = (int)$_GET['id'];
if (!empty($id)){ ... }
回答2:
your url is not correct try this
echo '<td align="center">'.$row[0].'-) <a href="newrecords.php?mid='.$id.'&id='.$row[0].'" >'. $row[3] . ' ' . $row[4] .'</a></td>';
回答3:
What you are doing? i think it is wrong. It will show url like "newrecords.php?mid=&id=44" this instead of your code you should try like this.
echo '<td align="center">'.$row[0].'-) <a href="newrecords.php?mid='.$id.'&id='.$row[0].'" >'. $row[3] . ' ' . $row[4] .'</a></td>';
来源:https://stackoverflow.com/questions/25177673/how-can-i-get-multiple-parameters-from-a-url-in-php