Thursday, June 9, 2011

pagenation and checkbox array

<style type="text/css">
<!--
.style7 {font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-size: 18px;
}
.style8 {color: #FFFFFF}
.style10 {color: #FFFFFF; font-weight: bold; }
-->
</style>
<table width="560" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4">&nbsp;</td>
  </tr>
  <tr>
    <td height="73" colspan="4"><div align="center"><span class="style7">Inbox</span></div></td>
  </tr>
  <tr>
    <td colspan="4"></td>
  </tr>
  <tr>
    <td width="77" bgcolor="#666666"><span class="style8"></span></td>
    <td width="168" bgcolor="#666666"><span class="style10">Name</span></td>
    <td width="183" bgcolor="#666666"><span class="style10">E-mail address</span></td>
    <td width="132" bgcolor="#666666"><span class="style10"> Subject</span></td>
  </tr>
  <tr>
    <td colspan="4"><div style="width:565px; height:auto; top:auto; border:#000000 1px solid">
     <p> <?php
      include("connect.php");
//Obtain the required page number
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
} // if
//Identify how many database rows are available
$query = "SELECT count(*) FROM tbl_inbox";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
//Calculate number of $lastpage
$rows_per_page = 10;
$lastpage      = ceil($numrows/$rows_per_page);
//Ensure that $pageno is within range
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} // if
if ($pageno < 1) {
   $pageno = 1;
} // if
//Construct LIMIT clause
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
//Issue the database query
$query = "SELECT * FROM tbl_inbox ORDER BY id DESC $limit";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

        $rs = mysql_query($query) or die("Invalid Query <br>$sql");
        $count=mysql_num_rows($rs);
        if($count==0)
        {
        echo'<br/><center><font style="font-family:Tahoma;font-size:11px;color:#990000">&nbsp;&nbsp;No Message in your Inbox</font></center><br/>';
        }
        while($row = mysql_fetch_array($result))
        {
        $rd=$row['rd'];
        echo'<form name="form1" method="post" action="">';
        if($rd=='y')
        {
        echo'<table>';
        echo'<tr>';
        echo'<td width="6">&nbsp;</td>';
        echo'<td width="60" ><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$row['id'].'"> </td>';       
        echo'<td width="170"><font face="Tahoma" size="1" color="black">'.$row['name'].'</font></td>';               
        echo'<td width="175"><font face="Tahoma" size="1" color="black"><a href="inbox_cont.php?id='.$row['id'].'" >'.$row['email'].'</a></font></td>';
        echo'<td width="116"><font face="Tahoma" size="1" color="black">'.$row['subject'].'</font></td>';   
        echo'</tr>';
        echo'</table>';
        echo'<hr align="center" width="100%"></hr>';
        }
        elseif($rd=='n')
        {
        echo'<table>';
        echo'<tr>';
        echo'<td width="6">&nbsp;</td>';
        echo'<td width="60" ><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$row['id'].'"> </td>';       
        echo'<td width="170"><b><font face="Tahoma" size="1" color="black">'.$row['name'].'</font></b></td>';               
        echo'<td width="175"><font face="Tahoma" size="1" color="black"><a href="inbox_cont.php?id='.$row['id'].'" <B>'.$row['email'].'</B></a></font></td>';
        echo'<td width="116"><b><font face="Tahoma" size="1" color="black">'.$row['subject'].'</font></b></td>';   
        echo'</tr>';
        echo'</table>';
        echo'<hr align="center" width="100%"></hr>';
        }
       
        }
        echo'<br/>';
//Construct pagination hyperlinks
if ($pageno == 1) {
   echo "  ";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'><img border='0' src='images/start.jpg' height='25' width='25'/></a> ";
   $prevpage = $pageno-1;
   echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><img border='0' src='images/arrow_left.jpg' height='25' width='25'/></a>";
} // if
echo " &nbsp;( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
   echo "";
} else {
   $nextpage = $pageno+1;
   echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'><img border='0' src='images/arrow_right.jpg' height='25' width='25'/></a>" ;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'><img border='0' src='images/end.jpg' height='25' width='25'/></a>";
} // if


?>
    </div></td>
  </tr>
  <tr>
    <td height="24" colspan="4" bgcolor="#666666"></p>
<input name="delete" type="submit" id="delete" value="Delete" /></td>
  </tr>
  <tr>  </tr>
  <tr>
    <td colspan="4"><?php
if(isset($_POST['delete']))
{
$checkbox = $_POST['checkbox']; //from name="checkbox[]"
$countCheck = count($_POST['checkbox']);

for($i=0;$i<$countCheck;$i++)
{
$del_id = $checkbox[$i];
$sql = "DELETE FROM tbl_inbox WHERE id='$del_id'";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=inbox_inbox.php\">";
}

}
?></td>
  </tr>
</table>

No comments:

Post a Comment