Pages

Sunday, November 16, 2014

Pagination on PHP

Its always possible that your SQL SELECT statement query may result into thousand of records. But its is not good idea to display all the results on one page. So we can divide this result into many pages as per requirement.

Paging means showing your query result in multiple pages instead of just put them all in one long page.

MySQL helps to generate paging by using LIMIT clause which will take two arguments. First argument as OFFSET and second argument how many records should be returned from the database.

Below is a simple example to fetch records using LIMIT clause to generate paging.

Example:

Try out following example to display 10 records per page.



Paging Using PHP


$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$rec_limit = 10;

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('test_db');
/* Get total number of records */
$sql = "SELECT count(emp_id) FROM employee ";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];

if( isset($_GET{'page'} ) )
{
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}
else
{
   $page = 0;
   $offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);

$sql = "SELECT emp_id, emp_name, emp_salary ".
       "FROM employee ".
       "LIMIT $offset, $rec_limit";

$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    echo "EMP ID :{$row['emp_id']}
".

         "EMP NAME : {$row['emp_name']}
".

         "EMP SALARY : {$row['emp_salary']}
".

         "--------------------------------
";



if( $page > 0 )
{
   $last = $page - 2;
   echo "Last 10 Records |";
   echo "Next 10 Records";
}
else if( $page == 0 )
{
   echo "Next 10 Records";
}
else if( $left_rec < $rec_limit )
{
   $last = $page - 2;
   echo "Last 10 Records";
}
mysql_close($conn);
?>

Sunday, May 18, 2014

Software Aplikasi windows dan linux

Berikut adalah daftar berbagai software di Linux dan padanannya di Windows. Data ini saya kutip dari situs The Linux Alternative Project.

Informasi lebih lanjut, fitur, screenshot dan lain2 silahkan klik link


3D Home Architect
Sweet Home 3D ( http://sweethome3d.sourceforge.net/index.html )

3D Studio Max
K-3D ( http://www.k-3d.org/ )
Wings 3D ( http://www.wings3d.com/ )
Art of Illusion ( http://www.artofillusion.org/ )
Blender ( http://www.blender.org/ )

Wednesday, May 14, 2014

Serious errors were found while checking the disk drive for /

Ubuntu 14.04 LTS trusty tahr versi stable sudah rilis di bulan april kemarin, sedikit menemukan masalah pasca instalasi via wubi, term disini laptop run dual boot os. apakah masalah itu?, ubuntu tidak berjalan dengan normal/abnormal boot. Muncul pesan
Serious errors were found while checking the disk drive for /

press [I] to ignore, press [S] to skip mounting and press [M] to mount manually
masalah terselesaikan dengan langkah berikut
1. in windows boot manager, select Ubuntu .
2. press any key and go in GUN Grub2 menu.
3. you can press "e" to edit GRUB2 boot entry. you need changing GRUB2 boot entry from "ro" to "rw",

Wednesday, March 5, 2014

Cara menambah swap di ubuntu

Swap adalah area atau ruang pada ‘hard-disk’ yang merupakan bagian dari memori virtual. Jadi, ia adalah memori sekunder (di luar memori primer/fisik yang berupa RAM). Memori Swap akan sangat berguna ketika memori utama sudah penuh terpakai, misalnya saat kita membuka banyak program/aplikasi yang rata-rata memakan banyak ‘resource’ pada RAM komputer kita.
Namun karena ketidaktahuan sebagian orang tentang pentingnya membuat partisi Swap, kemungkinan ia cuma membuat satu buah partisi saja, yaitu partisi untuk ‘root’ (file sistem Ubuntu). Bisa juga karena lupa.
Langkah-langkah membuat swap d ubuntu :

Cara hibernate di ubuntu 13.10 saucy salamandeer

If you’ve just updated to Ubuntu 12.04, you may notice an option missing in its system menu. The Hibernate option is now hidden by default, but you can get it back if you prefer to hibernate your system.
Hibernate is disabled by default because it can cause problems on some system configurations. You should perform a hibernate with a special command to test that it works properly before re-enabling it.

Hibernate vs. Suspend

The Suspend option is still available in Ubuntu’s system menu. Like hibernate, suspend saves your open programs and data, so you can quickly resume to your previous sate. However, suspend requires power — while in suspend mode, your computer will continue to draw a small amount of power. If the system loses power — for example, if you unplug a desktop computer from the power socket or a laptop’s battery empties, you’ll lose your work.