Im not sure where to put $action within the pagination so it knows which function it is dealing with ...
Code: Select all
function showdata ($search="") {
if ($search <> "") {
$sql = "SELECT id, userid, first_name, last_name, home_no, cell_no, work_no, email FROM address_book WHERE (first_name LIKE('$search%') OR last_name LIKE('%$search%')) AND userid = '".$_SESSIONї'userid']."' ORDER BY first_name ASC";
$action = "&action=search&find=$search";
} else {
$sql = "SELECT id, userid, first_name, last_name, home_no, cell_no, work_no, email FROM address_book WHERE userid = '".$_SESSIONї'userid']."' ORDER BY first_name ASC";
$action="";
}
dbconnect ();
// If current page number, use it
// if not, set one!
if(!isset($_GETї'page'])){
$page = 1;
} else {
$page = $_GETї'page'];
}
// Define the number of results per page
$max_results = 3;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM address_book WHERE userid = '".$_SESSIONї'userid']."' LIMIT $from, $max_results");
while($row = mysql_fetch_array($sql)){
$id = $rowї'id'];
$first_name = $rowї'first_name'];
$last_name = $rowї'last_name'];
$home_no = $rowї'home_no'];
$cell_no = $rowї'cel_no'];
$work_no = $rowї'work_no'];
$email = $rowї'email'];
?>
<table width="556" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<td width="70"><font class="txt"><b>Name:</b></font></td>
<td colspan="2"><font class="txt"><?php echo $rowї'first_name']; ?> <?php echo $rowї'last_name']; ?></font></td>
<td width="89"><font class="txt"><b>Email:</b></font></td>
<td colspan="2"><font class="txt"><a href="mailto:<?php echo $rowї'email']; ?>"><?php echo $rowї'email']; ?></a></font></td>
</tr>
<tr>
<td><font class="txt"><b>Home No:</b></font></td>
<td width="96"><font class="txt"><?php echo $rowї'home_no']; ?></font></td>
<td width="69"><font class="txt"><b>Work No:</b></font></td>
<td><font class="txt"><?php echo $rowї'work_no']; ?></font></td>
<td width="77"><font class="txt"><b>Mobile No:</b></font> </td>
<td width="96"><div align="left"><font class="txt"><?php echo $rowї'mobile_no']; ?></font></div></td>
</tr>
<tr>
<td colspan="6"><div align="center"><font class="txt" color="red"><a href='../index.php?pages=address_book&action=edit&id=<?php echo $rowї'id']; ?>'>Edit</a>
| <a href='../index.php?pages=address_book&action=delete&id=<?php echo $rowї'id']; ?>'>Delete</a></font></div></td>
</tr>
</table>
<hr align="center" width="98%">
<?php
}
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM address_book WHERE userid = '".$_SESSIONї'userid']."'"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<font class="txt"><< <a href="".$_SERVERї'PHP_SELF']."?pages=address_book&page=$prev">Previous</a> | </font>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "<font class="txt" color="#FF0000">$i </font>";
} else {
echo "<font class="txt"><a href="".$_SERVERї'PHP_SELF']."?pages=address_book&page=$i">$i</a> </font>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<font class="txt"> | <a href="".$_SERVERї'PHP_SELF']."?pages=address_book&page=$next">Next</a> >></font>";
echo "<br><br>";
}
}
echo "</center><br>";