Page 1 of 1
variable embeded in url
Posted: Mon Aug 26, 2002 11:47 am
by hermzz
i know how to build the url, but i dont know how to get a variable from it in another page, for example:
index.php3 builds a url called
http://www.myhost.com/id.php3?id=xx
how can i get the variable id=xx into id.php3
in other words, how can i get a variable embeded in the url to work?
with this id i have to get to show the rest of the row contents
Posted: Mon Aug 26, 2002 12:04 pm
by nielsene
$_GET["id"] will have the value from the url (php 4.1+)
$HTTP_GET_VARS["id"] in older versions
Posted: Mon Aug 26, 2002 3:07 pm
by Takuma
I recommend using $_GET if you got PHP4.1+
Posted: Mon Aug 26, 2002 3:28 pm
by hermzz
this is whati wrote but it gives me an T_ENCAPSED_AND_WHITESPACE in the second line, this is not the complete script but it's what matters.
this page calls itself in the second part. so first there is a search query that calls this page, it displays the results with a hyperlink that calls the page back ($PHP_SELF) with and added
?id=xx
basically the part that doesn't work is the first 4 or 5 lines, from
if ($id) { to
} else {
it won't put
printf("nombre: %s\n <br>", $myrow["autor"]); , because there is no id.
Code: Select all
if ($id) {
$result = mysql_query("SELECT * FROM letras WHERE id = $_GETї'id']");
$myrow = mysql_fetch_array(result,MYSQL_ASSOC) ;
printf("nombre: %s\n <br>", $myrowї"autor"]);
} else {
$result = mysql_query("SELECT * FROM letras WHERE autor = "" . $_POSTї'name'] . """);
if(!$result || !mysql_num_rows($result)) {
echo "<table width="100%" border="0" class='body'><tr><td>Query returned no results.</td></tr></table>";
} else {
print("<table width="100%" border="0" class='body'>");
print("<tr><td>Autor</td><td>Titulo</td><td>ID</td></tr>");
while($myrow = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("<tr><td><a href="%s?id=%s">%s</a></td><td>%s</td><td>%s</td></tr>\n", $PHP_SELF, $myrowї'id'], $myrowї'autor'], $myrowї'titulo'], $myrowї'id']);
}
echo "</table>";