variable embeded in url

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
hermzz
Forum Newbie
Posts: 2
Joined: Mon Aug 26, 2002 11:47 am
Location: Spain
Contact:

variable embeded in url

Post 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
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

$_GET["id"] will have the value from the url (php 4.1+)
$HTTP_GET_VARS["id"] in older versions
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I recommend using $_GET if you got PHP4.1+
hermzz
Forum Newbie
Posts: 2
Joined: Mon Aug 26, 2002 11:47 am
Location: Spain
Contact:

Post 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) &#123;
$result = mysql_query("SELECT * FROM letras WHERE id = $_GET&#1111;'id']");
$myrow = mysql_fetch_array(result,MYSQL_ASSOC) ;
printf("nombre: %s\n <br>", $myrow&#1111;"autor"]);
&#125; else &#123;
$result = mysql_query("SELECT * FROM letras WHERE autor = "" . $_POST&#1111;'name'] . """);
if(!$result || !mysql_num_rows($result)) &#123;
echo "<table width="100%" border="0" class='body'><tr><td>Query returned no results.</td></tr></table>";
&#125; else &#123;
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)) &#123;
printf("<tr><td><a href="%s?id=%s">%s</a></td><td>%s</td><td>%s</td></tr>\n", $PHP_SELF, $myrow&#1111;'id'], $myrow&#1111;'autor'], $myrow&#1111;'titulo'], $myrow&#1111;'id']);
    &#125;
echo "</table>";
Post Reply