Pagination with multiple rows and columns.

If you want to implement pagination in php with multiple rows and columns use the below code. Most possible that few things are not shown in the UI because code is not quoted well.

You need to just pass the number of columns as required so it will automatically calculated the number of rows.


<?php

$connection = mysql_connect(“LOCALHOST”,”USERNAME”,’PASSWORD’) or die(‘<html><body style=”font-family:arial;”><font style=”color:red;”><h1>Unable to connect to the server.<br>Please check your connection.<br/><span style=”color:blue;”>ERROR : ‘.mysql_error().'</span></h1></font></body></html>’);

$SelectDB = mysql_select_db(“Database NAME”) or die(‘<html><body><font style=”color:red;”><h1>Unable to connect to the specified database).<br>Please check database name.<br/><span style=”color:blue;”>ERROR: ‘.mysql_error().'</span></h1></font></body></html>’);

$i = 1;
$numcols = 10;                                                          // how many columns to display
$numcolsprinted = 0;                                            // no of columns so far
$numitems = count($city_arr);                        // Number of Items
$numrows = ceil($numitems/$numcols);   // Number of Rows

echo ‘‘;

for ($row=1; $row <= $numrows; $row++) {
      $cell = 0;
      echo ‘‘.”n”;

      for ($col=1; $col <= $numcols; $col++) {
            echo ‘ ‘.”n”;
      }

      echo ‘ ‘.”n”;
}

echo ‘‘.”n”;

if ($col===1) {
$cell += $row;

if($city_arr[$cell – 1] == ”) {
//do nothing….
} else {
if(is_array($city_arr2)) {
$sel2 = ”;

if(in_array($city_arr[$cell – 1], $city_arr2)) {
$sel2 = “checked=’checked’”;
} else {
//do nothing….

}
}

echo ‘‘;
echo “ ”;
}

print $city_arr[$cell – 1];
echo ‘‘;
} else {
$cell += $numrows;
echo ‘‘;

if($city_arr[$cell – 1] == ”) {

} else {
if(is_array($city_arr2)) {
$sel2 = ”;

if(in_array($city_arr[$cell – 1], $city_arr2)) {
$sel2 = “checked=’checked’”;
}
}

echo “ ”;
}

print $city_arr[$cell – 1];
echo ‘‘;
}

echo ‘ ‘;

?>

Posted in PHP | Tagged , , | Comments Off

Comments are closed.