2013-11-01 22 views
0

請問我需要幫助。我收到此通知:未定義的索引:Sn在C: xampp htdocs SchoolCare 分頁第一個try.php在線116

我做了分頁和我得到這個錯誤:

Notice: Undefined index: sn in C:\xampp\htdocs\SchoolCare\pagination first try.php on line 116 

這裏是我的代碼:

<?php 
require "../includes/dc_conect.php"; 

$sql1=("SELECT * FROM staffs WHERE staff_id='super_admin'"); 
$result1=mysql_query($sql1, $link) or die (mysql_error()); 
$dbfield1=mysql_fetch_assoc($result1); 
$count1=mysql_num_rows($result1); 

$sql=("SELECT COUNT(sn) FROM staffs ORDER BY sn ASC"); 
$query=mysql_query($sql, $link) or die (mysql_error()); 
$row=mysql_fetch_row($query); 


//here we have the total row counts chyke okoli 
$rows= $row[0]; 
//here is the number of result we wana display chyke okoli 
$page_rows= 10; 
// this tells us the page number of our last page---chyke okoli 
$last = ceil($rows/$page_rows); 
//make sure $last cannot be less than 1---chyke 
if ($last<1){ 
    $last=1; 
} 
//establish the $pagenum variable--chike 
$pagenum = 1; 
//get the page num var from the URL if its present else its equal to 1; 
if(isset($_GET['pn'])){ 
    $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']); 
} 
//make sure the pagenum is less than 1 and d last is nt more than d last 
if($pagenum < 1){ 
    $pagenum = 1; 
}elseif($pagenum > $last) 
    { 
    $pagenum = $last; 
    } 
//set the range of rows to query -----vitalischikeokoli 
$limit = 'LIMIT '.($pagenum - 1) * $page_rows.','.$page_rows; 
//write a query to return one page of row 
$sql=("SELECT sn, fname, sname, staff_id FROM staffs ORDER BY sn ASC $limit"); 
$query=mysql_query($sql, $link) or die (mysql_error()); 
//show the user what page they are into 
$textline1 = "Staff Records (<b>$rows</b>)"; 
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>"; 
//pagination Ctrl var 
$paginationCtrls = ''; 
//if more than 1 page result 
if($last != 1){ 
    /*First we check if we on page one if so we dont need the prev---vitalisokolichike---*/ 

    if($pagenum > 1){ 
     $previous = $pagenum - 1; 
     $paginationCtrls .='<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">PREV</a> &nbsp; &nbsp;'; 
     //render clickable number link that should appear at d left of the target page num 

     for($i = $pagenum-4; $i < $pagenum; $i++) 
     { 
     if($i > 0){ 
      $paginationCtrls .='<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> &nbsp; &nbsp;'; 
     } 
     } 
    } 
    //render tha target page number without link 
    $paginationCtrls .=''.$pagenum.' &nbsp; '; 
    //render d clikable number 
    for($i = $pagenum+1; $i <= $last; $i++){ 
     $paginationCtrls .='<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> &nbsp; &nbsp;'; 
     if($i >= $pagenum+4){ 
     break; 
     } 
    } 
    //check if we are on the last page then adding NEXT 
     if($pagenum != $last){ 
     $next = $pagenum + 1; 
     $paginationCtrls .='&nbsp; &nbsp;<a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">NEXT</a>'; 
     } 
} 

?> 

然後我echore了出來放在一個表

<table height="182" id="man_staff_table"> 
       <tr> 
        <td height="39"><div align="right" id="dboard"> 
        <div id="div2"><a href="../admin/admin_dash_board.php">Dashboard</a></div> 
        </div></td> 
        <td height="39">&nbsp;</td> 
        <td height="39">&nbsp;</td> 
        <td height="39">&nbsp;</td> 
        <td height="39">&nbsp;</td> 
        <td height="39">&nbsp;</td> 
        <td height="39"><div id="dboard"><a href="add_staff.php">Add a Staff</a></div></td> 
       </tr> 
       <tr> 
       <td width="119" height="17">&nbsp;</td> 
       <td width="268">&nbsp;</td> 
       <td width="13">&nbsp;</td> 
       <td width="31">&nbsp;</td> 
       <td width="15">&nbsp;</td> 
       <td width="195">&nbsp;</td> 
       <td width="112">&nbsp;</td> 
      </tr> 

       <tr> 
       <td height="39" colspan="7"><h3>Manage Staff Records</h3><hr></td> 
      </tr> 
       <tr> 
       <td height="17" colspan="7"><div align="right"><?php echo $textline2; ?></div></td> 
      </tr> 
       <tr> 
       <td height="21" colspan="7"><table width="960" align="center" class="imagetable"> 
        <tr> 
        <th width="49">S/N</th> 
        <th width="101">Surname</th> 
        <th width="118">First Name </th> 
        <th width="80">Staff ID </th> 
        <th colspan="4">&nbsp;</th> 
        </tr> 
        <?php do{ ?> 
        <tr> 
        <td><?php echo @$row['sn']; ?></td> 
        <td><?php echo @$row['sname']; ?></td> 
        <td><?php echo @$row['fname']; ?></td> 
        <td><?php echo @$row['staff_id']; ?></td> 
        <td width="273">&nbsp;</td> 
        <td width="31"><div align="center"><img src="../image/view_icon.png" alt="View" width="15" height="12"></div></td> 
        <td width="31"><div align="center"><img src="../image/edit_icon.png" alt="Edit" width="15" height="17"></div></td> 
        <td width="31"><div align="center"><img src="../image/delete_icon.png" alt="Delete" width="15" height="15"></div></td> 
        <?php } while($row=mysql_fetch_assoc($query)) ?> 
        </tr> 
       </table></td> 
      </tr> 
       <tr> 
       <td height="17" colspan="7"><div align="center" id="pagination_control"><?php echo $paginationCtrls; ?></div></td> 
      </tr> 
     </table> 

PLS我需要幫助,我只是使用@功能來靜音輸出,但這個特殊的角色是空的,它看起來不太好 ![1]

+0

試試'如果(isset($行[ 'SN'])); $行[ 'SN']; ' – user2092317

+0

丹尼爾我dnt得到?我的代碼行如何插入:if(isset($ row ['sn'])); $行[ 'SN']; – Legendchyke

回答

0

A do{} while()循環實際上並沒有獲取行直到循環結束,所以你運行的代碼與不存在的數據(或者說,從你的在獲取$行之前,SELECT COUNT(*)數據,因爲這是您最後一次分配$ row)。切換您的do{} while()while

while($row=mysql_fetch_assoc($query)){ 
    // now output your rows 
} 
+0

如果是這樣,他沒有得到'sname'的未定義索引,'fname' – user2092317

+0

我們怎麼知道他沒有? – aynber

+0

晚餐!!!!!!!!我調整像你說的==============它得到了修復!我非常感謝 – Legendchyke

相關問題