I ran two SQL queries in a page and want to pass those variable to anotherpage.. i know that i can pass one variable attached it to the anchor link but can we do that for two variables with single link?
The usual passing single variable:
<a href="page2.php?id=<?php echo $row['variable1'];?>" ><li style="font-size:14px;"><strong>LINK</strong></li></a>
On the other page(#2) we can call the passed variable using $id = $_GET["id"];
method..
Now as per my situation, is it possible for two variables:
<a href="page2.php?id=<?php echo $row['variable1'];?> ?id2=<?php echo $row2['variable2'];?>" ><li style="font-size:14px;"><strong>LINK</strong></li></a>
If it is possible, did i done anything wrong in the above code... Any Help is Appreciated..
You forgot to use the Ampersand char to add more variables "&"
try do some more nice code and cleaning some non acceptable chars in your case with the $_GET method.
<?php
function cleanvar($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$var_1 = cleanvar($row['variable1']);
$var_2 = cleanvar($row['variable2']);
?>
<a href="page2.php?id=<?php echo $var_1;?>&id2=<?php echo $var_2;?>"><li style="font-size:14px;"><strong>LINK</strong></li></a>
Maybe you can use some referer param like " &referer=mypage1.php" and create some condition like
if($_GET['referer'] == 'mypage1.php'){ //save or do something }else{ //nothing or do somthing}
hoping that helps you
I recommend you read a bit on the HTTP GET method. Here is a Wikipedia entry on what you are doing However for brevity passing multiple arguments requires an &, hence your query might look something like this:
<a href="page2.php?id=<?php echo $row['variable1'] . "&key=" . $row['variable2']; ?>"></a>