1. Setup how many rows to show per page
// how many rows to show per page
$rowsPerPage = 20;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
2. Set your query
$tbl_name="record"; // Table name
$sql="SELECT * FROM $tbl_name LIMIT $offset, $rowsPerPage";
$result=mysql_query($sql);
3. Display the result
while($rows=mysql_fetch_array($result)) {
echo $rows['id'];
echo $rows['name'];
}
?>
4. Display how many rows we have in database and page
// how many rows we have in database
$query = "SELECT COUNT(id) AS numrows FROM $tbl_name";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " $page ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " [Prev] ";
$first = " [First Page] ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " [Next] ";
$last = " [Last Page] ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
?>
Enjoy ubuntu... ;)
Popular Posts
- How to setting Internet and MMS for iPhone (Maxis, DiGi, Celcom, Xpax, U Mobile)
- How to setup MMS (CELCOM) for Sony Ericsson W810
- How do I install ArcGIS Desktop 9.3 for use with a local license?
- How to solve unable to receive MMS (Celcom,Maxis,Digi) messages on Blackberry Torch
- How to configure BlackBerry As Modem(Maxis) using Blackberry Desktop
Friday, June 19, 2009
Wednesday, June 17, 2009
How to display date format in PHP
Problem
I currently have
PHP Code:
echo $rows['date'];
which display date as "2009-06-17" (year, month, day)
Solution
PHP Code:
echo date('d m Y', strtotime($rows['date']));
Now i can display date as 22 06 2009
Enjoy ubuntu... ;)
I currently have
PHP Code:
echo $rows['date'];
which display date as "2009-06-17" (year, month, day)
Solution
PHP Code:
echo date('d m Y', strtotime($rows['date']));
Now i can display date as 22 06 2009
Enjoy ubuntu... ;)
Tuesday, June 16, 2009
How to unmount usb on ubuntu
1. Quote : umount /dev/sdb1 media/sdb1
umount: /dev/sdb1: not mounted
umount: media/sdb1: not mounted
Enjoy ubuntu... ;)
umount: /dev/sdb1: not mounted
umount: media/sdb1: not mounted
Enjoy ubuntu... ;)
How to mount usb on ubuntu
1. Quote : fdisk -l
Disk /dev/sda: 80.0 GB, 80026361856 bytes
240 heads, 63 sectors/track, 10337 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Disk identifier: 0x95aa95aa
Device Boot Start End Blocks Id System
/dev/sda1 * 1 3386 25598128+ 7 HPFS/NTFS
/dev/sda2 3387 10337 52548142+ f W95 Ext'd (LBA)
/dev/sda5 4920 5597 5120000 7 HPFS/NTFS
/dev/sda6 7629 10337 20480008+ 7 HPFS/NTFS
/dev/sda7 5598 7628 15350076 83 Linux
/dev/sda8 3387 3515 971869+ 82 Linux swap / Solaris
/dev/sda9 3515 3528 96358+ 83 Linux
/dev/sda10 3528 4205 5116671 83 Linux
Partition table entries are not in disk order
Disk /dev/sdb: 4011 MB, 4011851776 bytes
5 heads, 32 sectors/track, 48972 cylinders
Units = cylinders of 160 * 512 = 81920 bytes
Disk identifier: 0xe3b4e3b4
Device Boot Start End Blocks Id System
/dev/sdb1 * 51 48973 3913792 b W95 FAT32
2. Quote : mount /dev/sdb1 media/sdb1
Enjoy ubuntu... ;)
Disk /dev/sda: 80.0 GB, 80026361856 bytes
240 heads, 63 sectors/track, 10337 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Disk identifier: 0x95aa95aa
Device Boot Start End Blocks Id System
/dev/sda1 * 1 3386 25598128+ 7 HPFS/NTFS
/dev/sda2 3387 10337 52548142+ f W95 Ext'd (LBA)
/dev/sda5 4920 5597 5120000 7 HPFS/NTFS
/dev/sda6 7629 10337 20480008+ 7 HPFS/NTFS
/dev/sda7 5598 7628 15350076 83 Linux
/dev/sda8 3387 3515 971869+ 82 Linux swap / Solaris
/dev/sda9 3515 3528 96358+ 83 Linux
/dev/sda10 3528 4205 5116671 83 Linux
Partition table entries are not in disk order
Disk /dev/sdb: 4011 MB, 4011851776 bytes
5 heads, 32 sectors/track, 48972 cylinders
Units = cylinders of 160 * 512 = 81920 bytes
Disk identifier: 0xe3b4e3b4
Device Boot Start End Blocks Id System
/dev/sdb1 * 51 48973 3913792 b W95 FAT32
2. Quote : mount /dev/sdb1 media/sdb1
Enjoy ubuntu... ;)
Thursday, June 11, 2009
How to reset your MySQL root password under Windows
In case you forgot the root password for your MySQL database server running under Microsoft Windows, you can still access your database and even reset your password using the command prompt. However, first you should check your my.cnf file where your password is stored.
If you are using a new version of MySQL Server, such as 5.0, the methods here might not work for you, or slightly different actions may need to be applied.
1. Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
2. Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
3. Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
4. Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
5. Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
6. Enter "mysql" and press enter.
7. You should now have the MySQL command prompt working. Type "use mysql;" so that we switch to the "mysql" database.
8. Execute the following command to update the password:
UPDATE user SET Password = PASSWORD('NEW_PASSWORD') WHERE User = 'root';
However, you can now run any SQL command that you wish.
After you are finished close the first command prompt and type "exit;" in the second command prompt windows to disconnect successfully. You can now start the MySQL service.
Please note that the 8 step process above can differ depending on the MySQL version you are using, how you configured your server, etc. However, many times you can still easily work around a problem that you experience in any of the steps.
Enjoy ubuntu... ;)
Tq Andrew Pociu
If you are using a new version of MySQL Server, such as 5.0, the methods here might not work for you, or slightly different actions may need to be applied.
1. Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
2. Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
3. Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
4. Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
5. Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
6. Enter "mysql" and press enter.
7. You should now have the MySQL command prompt working. Type "use mysql;" so that we switch to the "mysql" database.
8. Execute the following command to update the password:
UPDATE user SET Password = PASSWORD('NEW_PASSWORD') WHERE User = 'root';
However, you can now run any SQL command that you wish.
After you are finished close the first command prompt and type "exit;" in the second command prompt windows to disconnect successfully. You can now start the MySQL service.
Please note that the 8 step process above can differ depending on the MySQL version you are using, how you configured your server, etc. However, many times you can still easily work around a problem that you experience in any of the steps.
Enjoy ubuntu... ;)
Tq Andrew Pociu
Wednesday, June 10, 2009
How to mount ntfs drive on Ubuntu
1. Install ntfs-3g.
Quote : apt-get install ntfs-3g
2. Create a folder in /media or /mnt (mkdir /media/windows)
3. Use
Quote : fdisk -l
to get the name of the NTFS drive (example: dev/sda1)
4. Add the drive into /etc/fstab so it mounts automatically.
Quote : /etc/fstab
Quote : /dev/sda1 /media/windows ntfs-3g defaults 0 0
Enjoy ubuntu... ;)
Subscribe to:
Posts (Atom)