2012-03-08 14 views
1

このSELECT COUNT(*)ページの名字を印刷しようとしています。 "'$ row [6]。' '。$ row [7]。'というコードを削除した場合、ページは正常に動作し、選択したユーザーの集計ポイント行は印刷されますが、ファーストネームと姓は印刷されません。SELECT COUNTと未定義オフセットの問題

* 177行目の 'database.php'スクリプトでエラーが発生しました:未定義のオフセット:6日時:3-8-2012 12:27:03私はこのコードを削除しないと、以下のメッセージが表示されます。 *

 <?php # index.php 

     // Include the configuration file for error management and such. 
     require_once ('./includes/config.inc.php'); 

     // Set the page title and include the HTML header. 
     $page_title = 'Individual Member Transactions'; 
     include ('includes/header_admin_user.html'); 

     // If no dealer_code variable exists, redirect the user. 
     if (!isset($_SESSION['admin_int_id'])) { 

      // Start defining the URL. 
      $url = 'http://' . $_SERVER['HTTP_HOST'] 
      . dirname($_SERVER['PHP_SELF']); 
      // Check for a trailing slash. 
      if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\')) { 
       $url = substr ($url, 0, -1); // Chop off the slash. 
      } 
      // Add the page. 
      $url .= '/login.php'; 

     ob_end_clean(); // Delete the buffer. 
     header("Location: $url"); 
     exit(); // Quit the script. 
     } 

     // Check for a valid user ID, through GET or POST. 
     if ((isset($_GET['id'])) && (is_numeric($_GET['id']))) 
      { // Accessed through view_users.php 
      $id = $_GET['id']; 

     } elseif ((isset($_POST['id'])) && (is_numeric($_POST['id']))) 
      { // Form has been submitted. 
      $id = $_POST['id']; 
     } else { // No valid ID, kill the script. 
      echo '<h1 id="mainhead">Page Error</h1> 
      <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; 
      include ('./includes/header_admin_user.html'); 
      exit(); 
     } 

     ?> 

     <h1 id="mainhead">Points Transactions</h1> 

      <div id="sidebar"> 

       <div id="statusbar"> 
      <p><span class="statusbar_highlight">Name:</span><br /> 
      <?php echo " {$_SESSION['adminfirstname']} " . " {$_SESSION['adminsurname']}<br> ";?></p> 
      <p><span class="statusbar_highlight">Status:</span><br /> 
      <?php echo " {$_SESSION['adminstatus']} ";?></p> 
      <p><span class="statusbar_highlight">Employer:</span><br /> 
      <?php echo " {$_SESSION['adminemployer']} ";?></p>  
      </div> 

      </div> 

      <div id="maincontent_results"> 

     <?php 

     require_once ('database.php'); // Connect to the db. 

     // Number of records to show per page: 
     $display = 1000; 

     // Determine how many pages there are. 
     if (isset($_GET['np'])) { // Already been determined. 
      $num_pages = $_GET['np']; 
     } else { // Need to determine. 

      // Count the number of records 
      $query = "SELECT COUNT(*) FROM tally_point, users WHERE tally_point.users_id = users.users_id ORDER BY tally_points_entry_date DESC"; 
      $result = @mysql_query ($query); 
      $row = @mysql_fetch_array ($result, MYSQL_NUM); 
      $num_records = $row[0]; 

      // Calculate the number of pages. 
      if ($num_records > $display) { // More than 1 page. 
       $num_pages = ceil($num_records/$display); 
      } else { 
       $num_pages = 1; 
      } 

     } // End of np IF. 

     // Determine where in the database to start returning results. 
     if (isset($_GET['s'])) { 
      $start = $_GET['s']; 
     } else { 
      $start = 0; 
     } 

     // Default column links. 
     $link1 = "{$_SERVER['PHP_SELF']}?sort=lna"; 
     $link2 = "{$_SERVER['PHP_SELF']}?sort=fna"; 
     $link3 = "{$_SERVER['PHP_SELF']}?sort=dra"; 

     // Determine the sorting order. 
     if (isset($_GET['sort'])) { 

      // Use existing sorting order. 
      switch ($_GET['sort']) { 
       case 'lna': 
        $order_by = 'tally_points_in ASC'; 
        $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd"; 
        break; 
       case 'lnd': 
        $order_by = 'tally_points_in DESC'; 
        $link1 = "{$_SERVER['PHP_SELF']}?sort=lna"; 
        break; 
       case 'fna': 
        $order_by = 'total ASC'; 
        $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd"; 
        break; 
       case 'fnd': 
        $order_by = 'total DESC'; 
        $link2 = "{$_SERVER['PHP_SELF']}?sort=fna"; 
        break; 
       case 'dra': 
        $order_by = 'tally_points_entry_date ASC'; 
        $link3 = "{$_SERVER['PHP_SELF']}?sort=drd"; 
        break; 
       case 'drd': 
        $order_by = 'tally_points_entry_date DESC'; 
        $link3 = "{$_SERVER['PHP_SELF']}?sort=dra"; 
        break;  
       default: 
        $order_by = 'tally_points_entry_date DESC'; 
        break; 
      } 

      // $sort will be appended to the pagination links. 
      $sort = $_GET['sort']; 

     } else { // Use the default sorting order. 
      $order_by = 'tally_points_entry_date DESC'; 
      $sort = 'dra'; 
     } 

     // Select tally rows for the selected user and the users details 
     $query = "SELECT ta.tally_points_in, ta.order_id, ta.total, DATE_FORMAT(ta.tally_points_entry_date, '%d-%m-%Y') AS dr, ta.users_id, us.users_id, us.users_first_name, us.users_surname 
        FROM tally_point AS ta, users AS us 
        WHERE ta.users_id=$id 
        AND us.users_id = ta.users_id 
        ORDER BY 
     ".$order_by." LIMIT ".$start.", ".$display; 
     $result = @mysql_query ($query); 

     // Table header. 
     echo ' ' . $row[6] . ' ' . $row[7] . ' 
     <table width="400" cellspacing="1" cellpadding="7"> 
     <tr class="top"> 
      <td align="left"><b><a href="' . $link2 . '">Date</a></b></td> 
      <td align="center"><b><a href="' . $link3 . '">Credit</a></b></td> 
      <td align="center"><b>Debit</b></td> 
      <td align="center"><b>Description</b></td> 
     </tr> 
     '; 

     // Fetch and print all the transactions. 
     $bg = '#ffffff'; // Set the background color. 

     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 

      $pointsitem = $row['order_id']; 

      $bg = ($bg=='#eaeced' ? '#ffffff' : '#eaeced'); // Switch the background color. 
      //$entries = floor($row['ltd_entry_amount']/200); 
      echo '<tr bgcolor="' . $bg . '">'; 
      echo '<td align="left">' . $row['dr'] . '</td>'; 
      echo '<td align="center"><strong>' . $row['tally_points_in'] . '</strong></td> '; 
      echo '<td align="center">' . $row['total'] . '</td>'; 

     // products the footer, close the table, and the form. 
     $str = '<td align="center">'; 
     if($pointsitem > '0') { 
     $str .='<strong><a href="view-ind-order.php?id=' . $pointsitem . '">Order Details</a></strong></td></tr>'; 
     } 
     else { 
     $str .='Monthly Points Update</td></tr>'; 
     } 
     echo $str; 
      } 

     echo '</table>'; 

     mysql_free_result ($result); // Free up the resources. 

     mysql_close(); // Close the database connection. 

     // Make the links to other pages, if necessary. 
     if ($num_pages > 1) { 

      echo '<br /><p>'; 
      // Determine what page the script is on. 
      $current_page = ($start/$display) + 1; 

      // If it's not the first page, make a Previous button. 
      if ($current_page != 1) { 
       echo '<a href="view_points_2.php?s=' . ($start - $display) . '&np=' . 
       $num_pages . '&sort=' . $sort .'">Previous</a> '; 
      } 

      // Make all the numbered pages. 
      for ($i = 1; $i <= $num_pages; $i++) { 
       if ($i != $current_page) { 
        echo '<a href="view_points_2.php?s=' . (($display * ($i - 1))) . 
        '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> '; 
       } else { 
        echo $i . ' '; 
       } 
      } 

      // If it's not the last page, make a Next button. 
      if ($current_page != $num_pages) { 
       echo '<a href="view_points_2.php?s=' . ($start + $display) . '&np=' . 
       $num_pages . '&sort=' . $sort .'">Next</a> '; 
      } 

      echo '</p>'; 

     } // End of links section. 

     ?> 

     <br class="clearboth" /> 

     </div> 
     </div> 
     </div> 

     <?php 
     include ('./includes/footer_admin_user.html'); // Include the HTML footer. 
     ?> 
+0

あなたのクエリは失敗しましたが、あなたは '@'でそれらを抑止したのでエラーは表示されません。それをデバッグするには、 'mysql_query()'から '@'を削除し、 'if(!$ result)echo mysql_error();'をチェックしてください。 –

+0

実際に起こっている問題を示す数行を除いてすべてのコードを削除すれば、良い答えを得ることができます。 – eouw0o83hf

答えて

1

あなたは何をする必要があります:エラーの前の行に

$row = @mysql_fetch_array ($result, MYSQL_NUM); 

。あなたが$rowを設定した最後の時間は一番上のコードのこの部分であったため、

今それはあなたのエラーを投げている。このような状況$row

// Count the number of records 
$query = "SELECT COUNT(*) FROM tally_point, users WHERE tally_point.users_id = users.users_id ORDER BY tally_points_entry_date DESC"; 
$result = @mysql_query ($query); 
$row = @mysql_fetch_array ($result, MYSQL_NUM); 

は一つだけの要素($row[0])を持っています。

+1

正解ですが、 '@' –

+0

ありがとうございますEduardoを取り除いてください。これは、ユーザがtally_pointテーブルに結果を持っていた場合にのみ有効です。ユーザーに結果がなかった場合、ユーザーの名前は表示されません。 – AdamMc

+0

もちろん、mysql_num_rows($ result)> 0'の前にチェックする必要があります。そうでなければ、それに応じて行動する必要があります。 –

関連する問題