artisticre Posted October 29, 2007 Share Posted October 29, 2007 A couple of things, below is my pagination code that is working. I want to see if its possible to make this into two columns instead of one list per page. Also, I am looking to do alphabetical pagination so if anyone has any tutorials on it would help thanks <? $server = "xxx"; $userid = "xxx"; $pass = "xxx"; $database = "xxx"; $limit = 6; $con = mysql_connect("$server","$userid","$pass") or die ("Huh? What Server"); $db = mysql_select_db("$database",$con) or die("I said WHAT database"); if (empty($offset) || $offset < 0) { $offset=0; } if (empty($index)) $index=0; $getrows = mysql_query("select * from directory", $con); $numrows=mysql_num_rows($getrows); $query = mysql_query("SELECT * from directory limit $offset,$limit", $con); $num=1; while ($result=mysql_fetch_array($query)){ $num = ($num < 15 ? $num : 1); $index++; /* Increment the line index by 1 */ echo " <div align=left width=100> <b>$result[lname]</b><br> $result[fname]<br> $result[children]</br> $result[address]</br> $result[city]</br> $result[zip]</br> $result[phone] </div> <hr color=#000 width=200></hr> "; if ($num==1 && $index!=$numrows) $num++; } if ($numrows <= $limit) { } else { if ($offset!=0) { $prevoffset=$offset-$limit; echo "<br><a onMouseOver=\"window.status='Previous $limit Results'; return true\"; href=\"$PHP_SELF?offset=$prevoffset&index=$prevoffset\"><B>[Previous]</B></a> "; } else echo "<b>[Previous]</b> "; $pages = intval($numrows/$limit); if ($numrows%$limit) { $pages++; } for ($i=1;$i<=$pages;$i++) { if (($offset/$limit) == ($i-1)) { echo " <b>$i</b> "; } else { $newoffset=$limit*($i-1); echo " <a onMouseOver=\"window.status='Page $i Results'; return true\"; href=\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>$i</B></a> \n"; } } if (!((($offset/$limit)+1)==$pages) && $pages!=1) { $newoffset=$offset+$limit; echo " <a onMouseOver=\"window.status='Next $limit Results'; return true\"; href=\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>[Next]</B></a><p>\n"; } else echo " <b>[Next]</b>"; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75215-pagination-help/ Share on other sites More sharing options...
Psycho Posted October 29, 2007 Share Posted October 29, 2007 For alphabetical pagination you just need to change your query to pull records in alphabetical order. $query = mysql_query("SELECT * FROM directory ORDER BY ????? LIMIT $offset,$limit", $con); When you say you want the records in two columns you need to be more specific. Do you want them in traditional newspaper type columns (top to bottom) or in left to right columns? The former is more complex, but easier to read in my opinion. If you want the data in two columns I would suggest using a table for displaying the data, else you need to create the HTML template of how you want the divs to be created. Quote Link to comment https://forums.phpfreaks.com/topic/75215-pagination-help/#findComment-380404 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.