Hi, there,

I am learning PHP/MySQL now, and got an sample code from
but when I test the code on my machine, it does not work as it
suppose to.

What it should do is: when you first run the php code, it
gives the names of the employees, each of which creates a link to the
detail info, for example, <a href=\"%s?id=%s\">%s %s</a><br>\n",
$PHP_SELF, $myrow["id"], $myrow["last"], $myrow["position"]>. When you
click any name, it should get the query value($id) from the URL, and use
it to search in the database.

It seems can't get the $id from the URL querystring, i.e., the html page
does not change after I click a specific name.

The code is the following:


$db = mysql_connect("localhost", "root");


// display individual record

if ($id) {

   $result = mysql_query("SELECT * FROM employees WHERE id=$id",$db);

   $myrow = mysql_fetch_array($result);

   printf("First name: %s\n<br>", $myrow["first"]);

   printf("Last name: %s\n<br>", $myrow["last"]);

   printf("Address: %s\n<br>", $myrow["address"]);

   printf("Position: %s\n<br>", $myrow["position"]);

} else {

    // show employee list

   $result = mysql_query("SELECT * FROM employees",$db);

    if ($myrow = mysql_fetch_array($result)) {

      // display list if there are records to display

      do {

        printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF,
$myrow["id"], $myrow["first"], $myrow["last"]);

      } while ($myrow = mysql_fetch_array($result));

    } else {

      // no records to display

      echo "Sorry, no records were found!";




Any comments and suggestions are appreciated.


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to