scm22ri Posted August 3, 2012 Share Posted August 3, 2012 Hi Everyone, Is it possible to pass multiple variables in a URL? I'm my example below if you click on "Write A Review" I'm passing the #id variable but can you pass other variables in that URL? http://whatsmyowncarworth.com/practiceTemplate/practice1/33/loans/table3.php <?php include('init.php'); /*$sql = "SELECT * FROM cars WHERE id='1' ORDER BY year ASC";*/ $sql = "SELECT * FROM dealers"; if ($result = mysql_query($sql)) { echo "<table border='1'>"; echo "<tr> <th>ID</th> <th>Name</th> <th>Reviews</th> <th>Address</th> <th>State</th> <th>City</th> <th>Website</th> "; // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($result)){ $id = $row['id']; $name = $row['name']; $address = $row['address']; $state = $row['state']; $city = $row['city']; $website = $row['website']; $maps = $row['maps']; $lat = $row['lat']; $lng = $row['lng']; echo("\t<tr>\n"); /*echo("\t\t<td>" . "$id" . "</td>\n");*/ /*echo("\t\t<td><a href='reviews2.php?id=" . $_GET['id'] . "'>" . "$id" . "</a>");*/ /*echo("\t\t<td><a href='reviews2.php?$id='>" . "$id" . "</a>");*/ /*echo "\t\t<td><a href='reviews2.php?$id'>$id</a>";*/ echo "\t\t<td><a href='reviews2.php?id=$id'>$id</a>"; /*echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n");*/ echo("\t\t<td>" . "<a href='reviews2.php?id=$name'>$name "); echo("\t\t<td>" . "<a href='reviews2.php?id=$id'>Write Review "); echo("\t\t<td>" . "$address" . "</td>\n"); echo("\t\t<td>" . "$state" . "</td>\n"); echo("\t\t<td>" . "$city" . "</td>\n"); echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n"); /*echo 'Error reporting: ' . ini_get('error_reporting') . '<br>Display errors: ' . ini_get('display_errors');*/ } echo "</table>"; } else { trigger_error(mysql_error()); // for development only; remove when in production } ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/ Share on other sites More sharing options...
Jessica Posted August 3, 2012 Share Posted August 3, 2012 ?var=1&other=2&third=3 Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366631 Share on other sites More sharing options...
pseud Posted August 3, 2012 Share Posted August 3, 2012 Yes, you'd use the semicolon for this, so the URL would read this for example: http://url.com?id=5;name=chris;function=example etc. Is this what you meant? Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366632 Share on other sites More sharing options...
KevinM1 Posted August 3, 2012 Share Posted August 3, 2012 Of course you can: http://www.example.com/index.php?id=1&somethingElse=45&anotherThing=bubba Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366633 Share on other sites More sharing options...
KevinM1 Posted August 3, 2012 Share Posted August 3, 2012 Yes, you'd use the semicolon for this, so the URL would read this for example: http://url.com?id=5;name=chris;function=example etc. Is this what you meant? Semicolons are irregular as separators. The ampersand is by far the most used method. Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366634 Share on other sites More sharing options...
pseud Posted August 3, 2012 Share Posted August 3, 2012 Yes, you'd use the semicolon for this, so the URL would read this for example: http://url.com?id=5;name=chris;function=example etc. Is this what you meant? Semicolons are irregular as separators. The ampersand is by far the most used method. Ahh okay, sorry for my misleading information. I've learned something here too Thanks, pseud Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366636 Share on other sites More sharing options...
hakimserwa Posted August 3, 2012 Share Posted August 3, 2012 by using & you can join multiple valuables. Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366641 Share on other sites More sharing options...
KevinM1 Posted August 3, 2012 Share Posted August 3, 2012 Yes, you'd use the semicolon for this, so the URL would read this for example: http://url.com?id=5;name=chris;function=example etc. Is this what you meant? Semicolons are irregular as separators. The ampersand is by far the most used method. Ahh okay, sorry for my misleading information. I've learned something here too Thanks, pseud More info: http://en.wikipedia.org/wiki/Query_string Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366642 Share on other sites More sharing options...
jazzman1 Posted August 3, 2012 Share Posted August 3, 2012 Be careful when you're using "&": http://htmlhelp.com/tools/validator/problems.html <!-- This is invalid! --> <a href="foo.cgi?chapter=1§ion=2©=3&lang=en">...</a> If you want to use "&" instead of "&", this url won't work in javascript: http://jazzman.com?ajax=_1243564780&lang=EN You could use "&" in js, to wrap it up a CDATA code. Quote Link to comment https://forums.phpfreaks.com/topic/266648-can-you-pass-multiple-variables-in-a-url/#findComment-1366654 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.