Jump to content

Help Passing values through URL


phpnewbie1979

Recommended Posts

I am having a difficult time getting values to pass through the URL.

I need to create two pages,  one that list the names of neighborhoods and link to the second page, which will show the rest of the information for each neighborhood. The problem I'm having is that the values aren't passing to the second page. Instead of getting

http://www.sitename.com/detail.php?id=1, what I'm getting is http://www.sitename.com/detail.php?id=$id. I can't figure out what I'm doing wrong. If anyone can point me in the right direction that would be great.

 

Page 1 code is

<?php

require_once "connect_to_mysql.php";
$query="SELECT id, name FROM table ORDER BY name";
$result=mysql_query($query);
$num=mysql_num_rows($result) or die(mysql_error());
?>
<table border="0" cellspacing="0" cellpadding="0">
<?php
$i=0;
while ($i <$num) {

$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
?>

<tr>
<td><a href='detail.php?id=$id'><?php echo $name; ?></a></td>
</tr>
<?php
$i++;
}
?>
</table>

 

Page 2 code is:

<?php 
require_once "connect_to_mysql.php";
$query = "SELECT * FROM table WHERE id=".$_GET['id'];
$result=mysql_query($query);
while($row = mysql_fetch_array($result)){
$name = $row["name"];
$fieldtwo = $row["fieldtwo"];
}
?>
<?php 
echo $name;
echo $fieldtwo; 
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/194365-help-passing-values-through-url/
Share on other sites

<?php

require_once "connect_to_mysql.php";
$query="SELECT id, name FROM table ORDER BY name";
$result=mysql_query($query);
$num=mysql_num_rows($result) or die(mysql_error());
?>
<table border="0" cellspacing="0" cellpadding="0">
<?php
$i=0;
while ($i <$num) {

$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
?>
<?php
echo "<tr><td><a href=\"detail.php?id=$id\">$name</a></td></tr>";
$i++;
}
?>
</table>

 

Updated ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.