Re: generate database driven web pages

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

 



On Tue, January 17, 2006 4:27 pm, Bing Du wrote:
> Hello everyone,
>
> Here is what I want to accomplish.  Query the backend database and
> generate a page listing all the staff members in table format that has
> name, title, phone and office address.  Staff name should be a link.
> Clicking the link should query the database again and use the
> information retrieved (e.g. projects, educations, etc.) to generate a
> page for each staff member.  A staff list page can be generated pretty
> easily.
>
> Now my question is how to keep the staffID (although it is not shown
> on
> the staff list page, but is queried along with name, title, etc.) so
> that when a staff name is clicked, his/her staffID will then be used
> to
> query the DB for personal information.
>
> Anybody have any handy working examples to give me some hints?

if (isset($_REQUEST['staff_id'])){
  $staff_id = (int) $_REQUEST['staff_id']; //crude but effective
filtering / validation
  $query = "select * from staff where staff_id = $staff_id";
  //next line is BAD CODE, for example purposes only:
  $detailed_profile = mysql_query($query) or die(mysql_error());
  $row = mysql_fetch_row($detailed_profile);
  //this is not so pretty...
  echo "<pre>"; var_dump($row); echo "</pre>\n";
}
else{
  $query = "select staff_id, name from staff order by name";
  //more bad code next line (see above):
  $staff = mysql_query($query) or die(mysql_error());
  while (list($staff_id, $name) = mysql_fetch_row($staff)){
    echo "<a
href=\"$_SERVER[PHP_SELF]?staff_id=$staff_id\">$name</a><br />\n";
  }
}

-- 
Like Music?
http://l-i-e.com/artists.htm

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux