Search

Alves Singh

Month

March 2016

PHP pagination

<?php
$num_rec_per_page=10;
if (isset($_GET[“page”])) { $page = $_GET[“page”]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
$sql = “SELECT * FROM student LIMIT $start_from, $num_rec_per_page”;
$rs_result = mysql_query ($sql); //run the query
?>
<table>
<tr><td>Name</td><td>Phone</td></tr>
<?php
while ($row = mysql_fetch_assoc($rs_result)) {
?>
<tr>
<td><?php echo $row[‘Name’]; ?></td>
<td><?php echo $row[‘Phone’]; ?></td>
</tr>
<?php
};
?>
</table>
<?php
$sql = “SELECT * FROM student”;
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);

echo “<a href=’pagination.php?page=1′>”.’|<‘.”</a> “; // Goto 1st page

for ($i=1; $i<=$total_pages; $i++) {
echo “<a href=’pagination.php?page=”.$i.”‘>”.$i.”</a> “;
};
echo “<a href=’pagination.php?page=$total_pages’>”.’>|’.”</a> “; // Goto last page
?>

Stop WordPress Ask FTP Credentials to Install New themes, plugins

Add below code in wp-config.php

define(‘FS_METHOD’, ‘direct’);

PHP function for clean string

function cleanString($str) {
        //$str = strip_tags($str);
        //$str = preg_replace('/<![\s\S]*?--[ \t\n\r]*>/', ' ', $str);
        $remove_this = array('%26', '%27', '%7C', '%5C', '%2D', '%2F');
        $put_this    = array(" ", " ", " ", " ","-","/");
        $str         = str_replace($remove_this, $put_this, $str);
        $clean = preg_replace("/[^a-zA-Z0-9:@ -\.,\/_|+ -\<\>\t\n\r]/", '', $str);
        //$clean = ucwords (trim($clean, ''));
        // $clean = preg_replace("/[\/_|+ -]+/", ' ', $clean);
        //$clean = preg_replace("/[\/_|+ ]+/", ' ', $clean);
        return trim($clean);
    }

Create a free website or blog at WordPress.com.

Up ↑