Jump to content

Inocorporating Pagination


taz321

Recommended Posts

Hi

 

I am new to pagination but have a general idea on what it does.

 

Basically i have a helpdesk system and people would submit tickets for any technical issues they have.

Now i have a page where the list of tickets go on forever (about 60 tickets).

How would i go about making sure it displays only the first 10 results, and then have another 10 results showing on another page (if you know what i mean).

 

Basically heres my code so far, which displays the tickets (the data in the database)

 

while($row= mysql_fetch_array($result)){?></td>

    <td height="35"><div align="center" class="style7"><?php echo $row['formID'];?></div></td>

    <td height="35"><div align="center" class="style7"><?php echo $row['issuetitle'];?></div></td>

    <td height="35"><div align="center" class="style7"><?php echo $row['datesubmitted'];?></div></td>

    <td height="35"><div align="center" class="style7"><?php echo $row['systemaffected'];?></div></td>

    <td height="35"><div align="center"><span class="style7"><?php echo $row['prioritylevel'];?></span></div></td>

    <td height="35"><div align="center"><span class="style7"><?php echo $row['teamname'];?></span></div></td>

    <td height="35"><div align="center" class="style7"><?php echo $row['employeeID'];?></div></td>

 

 

How would i go about doing pagination ?

 

Any help would be appreciated

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/
Share on other sites

Iv had a go, but doest seem to be working, any ideas ?

 

<?php

$query1 = mysql_query("SELECT * FROM form LIMIT $startrow, 10")or die (mysql_error());

if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
    $startrow = 0;

    } else {
    $startrow = (int)$_GET['startrow'];

}

?>

 

 

 

 

Not quite sure what else to do, i have inputted 12 rows of data in the database and i only want the first 10 to display, but on my screen after implementing the above code, all 12 are still shown.

 

Any ideas

 

Thats not a pagination, a pagination is much longer written. Try the PHP.about one

Hi there, here's an excellent script, but you have to put it in different parts or it won't run.  I really like this script, and then if you want to swap background colors there's some more code.  Let me know if you want that, but here's pagination first.

 

The first part that I'm cutting is after establishing connection to MySQL

 

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

// Number of records to show per page:

$display = 11;

 

// 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 uploads ORDER BY date_entered 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.

 

 

$first = TRUE; // Initialize the variable.

 

if (isset($_GET['s'])) {

$start = $_GET['s'];

} else {

$start = 0;

}

 

// Query the database.

--------------------------------------------

 

The second part starts after you close the connection to the db

// Make the links to other pages, if necessary.

if ($num_pages > 1) {

 

echo '<br /><p> <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_files_tables.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_files_tables.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_files_tables.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';

}

 

echo '</p>';

 

} // End of links section.

 

 

 

Am i along the right lines here - this is the code so far...(you may see there is some other code, but that is for other purposes which hopefully shudnt interrupt with the current code.

 

<?php

session_start();
if (isset($_SESSION['username']) == false){
	header("Location:login.php");
	exit();
}


require "connect.php";
$sortby = $_GET['var'];
$query = "select * from form ORDER by $sortby";
$result = mysql_query($query, $connection) or die ("MySQL Error: ".mysql_error());


$display = 6;
if (!isset($_GET['np'];	{
   $num_pages = $_GET['np'];
}
else {

$query1 = "SELECT COUNT(*) FROM form";
   	$result1 = @mysql_query ($query1);
   	$row = mysql_fetch_array ($result1, MYSQL_NUM);
   	$num_records = $row[0];

f ($num_records > $display) { 
      $num_pages = ceil ($num_records/$display);
   } else {
      $num_pages = 1;
   }

} 


	$first = TRUE; 

if (isset($_GET['s'])) {
   		$start = $_GET['s'];
	} else {

   			$start = 0;
	}



?>

g'day Taz...  It's quite simple really.  You just need to put the code where I had mentioned.  Would you like to see my entire script?  If you want, I have an email address that I use for this sort of stuff, and I can show you the whole script and how it works if you want, but it would be sooo much easier if you were to email me, especially that my database is for yacht crew and I don't feel like posting it in a public forum but am totally happy giving you my yahoo address.  It's [email protected]

 

Cheers,

 

Alex

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.