...

View Full Version : pagination alignment



eschuppe
03-29-2009, 12:00 AM
Hello everyone,

I recently add pagination limit the displays on a page, however, I'm trying to change the alignment ( I've tried td align , div align, p align) nothing seemed to change the location, or if it did it apearred there were breaks.
you can view the script at
www.ericschuppe.com/usercheckouts.php



<link href="styles.css" rel="stylesheet" type="text/css">
<?php


include ('dbc.php'); // Connect to the data base.





$max = 10; //amount of articles per page. change to what to want

$p = $_GET['p'];

if(empty($p))

{

$p = 1;

}

$limits = ($p - 1) * $max;

//view the news article!

if(isset($_GET['act']) && $_GET['act'] == "view")

{

$id = $_GET['id'];

$sql = mysql_query("SELECT * FROM checkout WHERE id = '$id'");

while($r = mysql_fetch_array($sql))

{

$full_name = $r['full_name'];

$user_idnum = $r['user_idnum'];

$date = $r['date'];

$book = $r['book'];

$returned = $r['returned'];

echo "<div><p>$full_name</p><p>$user_idnum</p><p>$date</p></div>";

}



}else{



//view all the news articles in rows

$sql = mysql_query("SELECT full_name,user_idnum,DATE_FORMAT(`date`, '%m/%d/%Y %I:%i %p'),book,returned FROM checkout LIMIT ".$limits.",$max") or die(mysql_error());

//the total rows in the table

$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM checkout"),0);

//the total number of pages (calculated result), math stuff...

$totalpages = ceil($totalres / $max);

//the table

echo '<table align="center" cellspacing="2" cellpadding="2"><tr><td align="left"><b>Name</b></td><td align="center"><b>ID</b></td><td align="center"><b>Date</b></td><td align="center"><b>Book</b></td><td align="center"><b>Returned</b></td></tr><tr>';

while($r = mysql_fetch_array($sql))

{
while ($r = mysql_fetch_array($sql, MYSQL_NUM)) {
echo "<tr><td align=\"left\">" .
stripslashes($r[0]) . "</td>
<td align=\"left\">$r[1]</td>
<td align=\"left\">$r[2]</td>
<td align=\"left\">$r[3]</td>
<td align=\"left\">$r[4]</td><tr>\n";

}

}

//close up the table

echo "</tr></table>";

for($i = 1; $i <= $totalpages; $i++){

//this is the pagination link

$counter = "<a href='usercheckouts.php?p=$i'>$i</a>";
echo "<span class=\"csstables\">$counter</span>";

}

}



?>
Thank you agian.

ShaneC
03-29-2009, 12:08 AM
Well this is more a HTML/CSS problem despite its association with PHP but I'll do my best to help you out.

Try taking this part:



<?php

for($i = 1; $i <= $totalpages; $i++){

//this is the pagination link

$counter = "<a href='usercheckouts.php?p=$i'>$i</a>";
echo "<span class=\"csstables\">$counter</span>";

}

?>
And replace it with this (adding the two echos before an after):



<?php

echo( "<div style='text-align: center;'>" );

for($i = 1; $i <= $totalpages; $i++){

//this is the pagination link

$counter = "<a href='usercheckouts.php?p=$i'>$i</a>";
echo "<span class=\"csstables\">$counter</span>";

}

echo( "</div>" );

?>

sea4me
03-29-2009, 12:49 AM
Well this is more a HTML/CSS problem despite its association with PHP but I'll do my best to help you out.

Try taking this part:



<?php

for($i = 1; $i <= $totalpages; $i++){

//this is the pagination link

$counter = "<a href='usercheckouts.php?p=$i'>$i</a>";
echo "<span class=\"csstables\">$counter</span>";

}

?>
And replace it with this (adding the two echos before an after):



<?php

echo( "<div style='text-align: center;'>" );

for($i = 1; $i <= $totalpages; $i++){

//this is the pagination link

$counter = "<a href='usercheckouts.php?p=$i'>$i</a>";
echo "<span class=\"csstables\">$counter</span>";

}

echo( "</div>" );

?>


I don't think that would work...

I think this would:



<?php

echo( "<center>" );

for($i = 1; $i <= $totalpages; $i++){

//this is the pagination link

$counter = "<a href='usercheckouts.php?p=$i'>$i</a>";
echo "<span class=\"csstables\">$counter</span>";

}

echo( "</center>" );

?>


BTW: That code can't be validated but it works :)

ShaneC
03-29-2009, 01:24 AM
Pray tell, why wouldn't that work?

A div has an automatic width of 100%. You are aligning the numbers in the middle of it. The <center> tag is essentially doing something similar, but it will A) Not validate B) Not be supported in some browsers/circumstances.

I just used Firebug on your website to modify it using the changes I suggested. It worked exactly as I intended: http://i43.tinypic.com/64jgix.jpg

eschuppe
03-29-2009, 01:53 AM
Thanks Shane C. your method worked perefect!

sea4me
03-29-2009, 06:59 AM
humm....

looks like I didn't learn HTML that good.... :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum