SoS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, All:

I'm a beginner of PHP. While trying the code from
a tutorial, I encountered the following problem.

The variable $id can not be transfered to my server.
You can find the code at the end of this email. When
I visit http://mydomain.com/test.php?id=1
it always shows the list of the database instead
of a perticular record.

I appreciate your kind helps!

Zhan Xu
EECS Department
Case Western Reserve University


<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
// 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!";	

    }

}
?>

</body>
</html>

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux