Another question about URL-passed vars
Posted: Wed Nov 24, 2004 2:42 pm
Ok, I made a page showing a list of all the social studies teachers from my school. It basically displays info from a database. I created a link on each teachers name to a page called "view.php" that is specific to every teacher. To clarify, here is my script on the page "teachers.php":
On the page that will display a teachers biography (view.php), I need to read what the $id variable is that was tacked onto the URL. For example, how would I read the $id if the URL= "http://***.com/view.php?id=1" Sorry if my question is confusing.
Code: Select all
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$result = mysql_query("select count(*) from teachers");
$number = mysql_result($result, 0);
$query="SELECT * FROM teachers ORDER BY id ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$username=mysql_result($result,$i,"username");
$subjects=mysql_result($result,$i,"subjects");
$phone=mysql_result($result,$i,"phone");
$email=mysql_result($result,$i,"email");
echo "
<tr>
<td width='25%'>
<p align='center'><a href="view.php?id=$id">$username</a></td>
<td width='25%'>
<p align='center'>$subjects</td>
<td width='25%'>
<p align='center'>$phone</td>
<td width='25%'>
<p align='center'><a href="mailto:$email?subject=School">$email</a></td>
</tr>
";
$i++;
}