Jump to content

Easiest way for me to paginate my database results?


INeedAGig

Recommended Posts

Hey there, I have never really done pagination before and I was wondering if anyone can take a look at my code and help me with coding pagination? This database will be storing a lot of information and I am going to have the need to break it into multiple pages.

 

The following code is the code from my results page, which is where I assume I will need to code the pagination. This is the page that displays all of the results after everything is processed and entered into the database in a different php file.

 

<?php
$username="removed_for_this_post"; //Database Username
$password="removed_for_this_post"; //Database Password
$database="removed_for_this_post"; //Database Name

mysql_connect("localhost",$username,$password); //Connection to database
@mysql_select_db($database) or die("ALERT! Database not found!"); //Selection of database
$query="SELECT * FROM leads ORDER by id DESC"; //Database table to query
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<html>
<head>
<link href="db_style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrap">
<div id="header">
<div id="hdr_content">
</div>
</div>
<br><br><br><br>
<center>
<table border="1" bordercolor="#000000" cellspacing="2" cellpadding="10">
<tr>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Name</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">E-Mail</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Age</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Gender</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Location</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Home Phone</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Other Phone</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Best Time to Reach</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Referrer</font></th>
<th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Options</font></th>
</tr>
</div>
<div id="footer">
<div class="footer_content">
<font class="footer_header">
</div>
</div>
<?php
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id"); //Unique ID Field
$name=mysql_result($result,$i,"name"); //Name
$email=mysql_result($result,$i,"email"); //EMail Address
$age=mysql_result($result,$i,"age"); //Age
$gender=mysql_result($result,$i,"gender"); //Gender
$location=mysql_result($result,$i,"location"); //City of Residence
$homephone=mysql_result($result,$i,"homephone"); //Home Phone Number
$otherphone=mysql_result($result,$i,"otherphone"); //Secondary Phone Number
$besttime=mysql_result($result,$i,"besttime"); //Best Time to Reach
$referrer=mysql_result($result,$i,"referrer"); //Referrer
?>
<tr>
<td align="center" bgcolor="#CCCCCC"><font class="lead_txt"><? echo $name; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $email; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $age; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $gender; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $location; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $homephone; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $otherphone; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $besttime; ?></font></td>
<td align="center" bgcolor="#CCCCCC"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $referrer; ?></font></td>
<td bgcolor="#01337f""><a href="db_edit.php?id=<?php echo $id; ?>"><img src="edit.png" width="25" height="25" alt="Edit"></a>   <a href="db_remove.php?id=<?php echo $id; ?>"><img src="delete.png" width="25" height="25" alt="Delete"></a>   <a href="email_lead.php?id=<?php echo $name, $email; ?>"><img src="email.png" width="25" height="25" alt="E-Mail"></a></td>
</tr>
</center>
</font>
</body>
</html>
<?php
$i++;
}
echo "</table>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.