Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2004, 11:28 AM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Nikolai,
I tried what u said and i changed all my "window.open()" to "alert()"

Now i get this message when i click on my users: (a window pops up saying ?action=view_record&userid=judy )

Please tell me what the problems are, i have attached my code. All text in red is what i have altered since last post:
Thanks a lot.

<?php
include "./common_db.inc";
?>

<HTML>
   <HEAD>
   <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
   <!--
   function open_window(url) {
           alert(url,''); }
   //-->
   </SCRIPT>
   <TITLE>User Record Viewer</TITLE>
   </HEAD>
   <BODY>

   <?php
function list_records() {
   global $default_dbname, $user_tablename;
   global $default_sort_order, $default_order_by, $records_per_page;
   global $sort_order, $order_by, $cur_page;
   global $PHP_SELF;

   $link_id = db_connect($default_dbname);
   if(!$link_id) error_message(sql_error());

   $query = "SELECT count(*) FROM $user_tablename";



   $result = mysql_query($query);
   if(!$result) error_message(sql_error());

   $query_data = mysql_fetch_row($result);
   $total_num_user = $query_data[0];
   if(!$total_num_user) error_message('No User Found!');
   $page_num = $cur_page + 1;

   $total_num_page = $last_page_num
                   = ceil($total_num_user/$records_per_page);

   html_header();

   echo "<CENTER><H3>$total_num_user users found. Displaying the page
                     $page_num out of $last_page_num.</H3></CENTER>\n";

   if(empty($order_by)) {
      $order_by_str = "ORDER BY $default_order_by";
      $order_by = $default_order_by;
   }
   else $order_by_str = "ORDER BY $order_by";
   if(empty($sort_order)) {
      $sort_order_str = $org_sort_order = $default_sort_order;
      $sort_order = 'DESC';
   }
   else {
      $sort_order_str = $org_sort_order = $sort_order;
      if($sort_order == 'DESC') $sort_order = 'ASC';
      else $sort_order = 'DESC';
   }

   if(empty($cur_page)) {
      $cur_page = 0;
   }
     $limit_str = "LIMIT ". $cur_page * $records_per_page .
                                     ", $records_per_page";
   $query = "SELECT usernumber, userid, username FROM $user_tablename
                                  $order_by_str $sort_order_str $limit_str";

   $result = mysql_query($query);
   if(!$result) error_message(sql_error());
?>

<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">
   <TR>
      <TH WIDTH="25%" NOWRAP>
         <A HREF="<?php echo "$PHP_SELF?action=list_records&
                                  sort_order=$sort_order&
                                  order_by=usernumber"; ?>">
         User Number
         </A>
      </TH>
      <TH WIDTH="25%" NOWRAP>
         <A HREF="<?php echo "$PHP_SELF?action=list_records&
                                     sort_order=$sort_order&
                                     order_by=userid"; ?>">
         User ID
         </A>
      </TH>
      <TH WIDTH="25%" NOWRAP>
         <A HREF="<?php echo "$PHP_SELF?action=list_records&
                                     sort_order=$sort_order&
                                     order_by=username"; ?>">
            User Name
         </A>
      </TH>
      <TH WIDTH="25%" NOWRAP>Action</TH>
   </TR>
<?php

   while($query_data = mysql_fetch_array($result)) {
      $usernumber = $query_data["usernumber"];
      $userid = $query_data["userid"];
      $username = $query_data["username"];
      echo "<TR>\n";
      echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$usernumber</TD>\n";
      echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$userid</TD>\n";
      echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$username</TD>\n";
      echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">
            <A HREF=\"javascript:alert('$PHP_SELF?action=view_rec ord&userid=$userid');\">View Record</A></TD>\n";
      echo "</TR>\n";
   }
?>
</TABLE>
</DIV>
<?php
   echo "<BR>\n";
   echo "<STRONG><CENTER>";
   if($page_num > 1) {
      $prev_page = $cur_page - 1;

      echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&cur_page=0\">[Top]</A>";

      echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&
                                cur_page=$prev_page\">[Prev]</A> ";
   }
   if($page_num < $total_num_page) {
      $next_page = $cur_page + 1;
      $last_page = $total_num_page - 1;

      echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&
                                cur_page=$next_page\">[Next]</A> ";

      echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&
                                cur_page=$last_page\">[Bottom]</A>";
   }

   echo "</STRONG></CENTER>";
   html_footer();
}

function view_record() {
   global $default_dbname, $user_tablename, $access_log_tablename;
   global $userid;
   global $PHP_SELF;

   if(empty($userid)) error_message('Empty User ID!');

   $link_id = db_connect($default_dbname);

   if(!$link_id) error_message(sql_error());

   $query = "SELECT usernumber, userid, username,
                    usercountry, useremail, userprofile,
                    registerdate, lastaccesstime FROM $user_tablename
                    WHERE userid = '$userid'";
   $result = mysql_query($query);

   if(!$result) error_message(sql_error());

   $query_data = mysql_fetch_array($result);
   $usernumber = $query_data["usernumber"];
   $userid = $query_data["userid"];
   $username = $query_data["username"];
   $usercountry = $query_data["usercountry"];
   $useremail = $query_data["useremail"];
   $userprofile = $query_data["userprofile"];
   $registerdate = $query_data["registerdate"];

   $lastaccesstime = substr($query_data["lastaccesstime"], 0, 4) . '-' .
            substr($query_data["lastaccesstime"], 4, 2) . '-' .
            substr($query_data["lastaccesstime"], 6, 2) . ' ' .
            substr($query_data["lastaccesstime"], 8, 2) . ':' .
            substr($query_data["lastaccesstime"], 10, 2) . ':' .
            substr($query_data["lastaccesstime"], 12, 2);

   html_header();
   echo "<CENTER><H3>
         Record for User No.$usernumber - $userid($username)
         </H3></CENTER>";

?>
<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">
   <TR>
      <TH WIDTH="40%">Country</TH>
      <TD WIDTH="60%"><?php echo $usercountry ?></TD>
   </TR>
   <TR>
      <TH WIDTH="40%">Email</TH>
      <TD WIDTH="60%"><?php echo "<A HREF=\"mailto:$useremail\">$useremail</A>"; ?></TD>
   </TR>
   <TR>
      <TH WIDTH="40%">Profile</TH>
      <TD WIDTH="60%"><?php echo $userprofile ?></TD>
   </TR>
   <TR>
      <TH WIDTH="40%">Register Date</TH>
      <TD WIDTH="60%"><?php echo $registerdate ?></TD>
   </TR>
   <TR>
      <TH WIDTH="40%">Last Access Time</TH>
      <TD WIDTH="60%"><?php echo $lastaccesstime ?></TD>
   </TR>
</TABLE>
</DIV>
<?php
   echo "\n";
   $query = "SELECT page, visitcount, accessdate FROM $access_log_tablename
             WHERE userid = '$userid'";

   $result = mysql_query($query);
   if(!$result) error_message(sql_error());
   if(!mysql_num_rows($result))
      echo "<CENTER>No access log record for $userid ($username).</CENTER>";
   else {
      echo "<CENTER>Access log record(s) for $userid ($username).</CENTER>";
?>
<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">
   <TR>
      <TH WIDTH="40%" NOWRAP>Web Page</TH>
      <TH WIDTH="20%" NOWRAP>Visit Counts</TH>
      <TH WIDTH="40%" NOWRAP>Last Access Time</TH>
   </TR>
<?php
      while($query_data = mysql_fetch_array($result)) {
         $page = $query_data["page"];
         $visitcount = $query_data["visitcount"];
         $accessdate = substr($query_data["accessdate"], 0, 4) . '-' .
                  substr($query_data["accessdate"], 4, 2) . '-' .
                  substr($query_data["accessdate"], 6, 2) . ' ' .
                  substr($query_data["accessdate"], 8, 2) . ':' .
                  substr($query_data["accessdate"], 10, 2) . ':' .
                  substr($query_data["accessdate"], 12, 2);

         echo "<TR>\n";
         echo "<TD WIDTH=\"40%\">$page</TD>\n";
         echo "<TD WIDTH=\"20%\" ALIGN=\"CENTER\">$visitcount</TD>\n";
         echo "<TD WIDTH=\"40%\" ALIGN=\"CENTER\">$accessdate</TD>\n";
         echo "</TR>\n";
      }
?>
   </TR>
</TABLE>
</DIV>
<?php

   }

   html_footer();
}




switch($action) {
   case "view_record":
      view_record();
   break;
   default:
      list_records();
   break;
}

if (!isset($_GET['action']))
$action=$_Get['action'];
else $action='list_records';
if (!isset($_GET['userid']))
$userid=$_GET['userid'];
else $userid=null;
?>



 
Old March 28th, 2005, 10:05 AM
Registered User
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Snib
 Hm.. all I can think of is that you had a typo or two.

This should work:

<A HREF=\"javascript:window.open('$PHP_SELF?action=vi ew_record&
        userid=$userid');\">View Record</A></TD>\n";

Maybe it would be easier if you just made a function called open_window().

Try adding this to your JavaScript code somewhere:

function open_window(url)
{
window.open(url,' ');
}

Let me know if this works.

Snib

P2P Member
<><


Thanks for that tip! I've been struggling for hours trying to make this work so I can keep turning pages in this intriguing php journey into databases and beyond!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
any idea to view xml as it is but in hieratic view seco XSLT 2 January 17th, 2008 08:49 AM
Help Grid View Drop Down List, view all jskinner123 ASP.NET 2.0 Basics 0 November 25th, 2007 06:25 PM
show data record in grid view - sqlserver2005 vinodonline2000 ASP.NET 2.0 Basics 5 August 10th, 2007 05:24 AM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.