I have a code that division a data from MySql table to pages,
My question is, if this code is an efficient (upload fast)?
If not tell me please how improve this code to make him more efficient.
(I don't write this code)
Sorry about my english🙁
<table width="100%">
<tr><td>
<?php
include ("config.php");
mysql_pconnect( "localhost", "$username", "$password")
or die( "Unable to connect to SQL server");
mysql_select_db( "$db_name") or die( "Unable to select database");
$query = mysql_query("SELECT count(*) as total FROM `members`") or die(mysql_error());
$row = mysql_fetch_array($query,MYSQL_ASSOC);
$numrows = $row['total'];
if (empty($offset)) {
$offset=0;
}
$query = "SELECT user, pass, email, id FROM members order by id DESC limit $offset,$limit";
$result = mysql_query ($query)
or die ("query 2 failed");
while ($row = mysql_fetch_row ($result))
{
for ($i = 0; $i < mysql_num_fields ($result); $i++)
{
if ($i > 0)
print ("
");
if ($i == 0){
print "<b>Name: </b>";
}
else if ($i == 1){
print "<b>Date: </b>";
}
else if ($i == 2){
print "<b>Email: </b>";
}
else{
print "<b>Comment:</b>
";
}
print ($row[$i]);
}
print "
<center><hr></center>";
print ("<P>");
}
if ($offset >= 3) {
$prevoffset = $offset - $limit;
print "<a href=\"?offset=$prevoffset\">PREV</a> \n";
}
$pages=intval($numrows/$limit);
if ($pages < ($numrows/$limit)){
$pages=($pages + 1);
}
for ($i = 1; $i <= $pages; $i++) {
$newoffset = $limit*($i-1);
if ($newoffset == $offset) {
print "$i \n";
} else {
print "<a href=\"?offset=$newoffset\">$i</a> \n";
}
}
//show next if not last
if (! ( ($offset/$limit) == ($pages - 1) ) && ($pages != 1) ) {
$newoffset = $offset+$limit;
print "<a href=\"?offset=$newoffset\">NEXT</a><p>\n";
}
?>
</td></tr>
</table>
</body>
</html>