ขอวิธีแสดงตัวแบ่งหน้าข้อมูลตามข้อมูลที่เรามีหน่อยค่ะ

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

moomai
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 680
ลงทะเบียนเมื่อ: 07/12/2016 10:54 am

ขอวิธีแสดงตัวแบ่งหน้าข้อมูลตามข้อมูลที่เรามีหน่อยค่ะ

โพสต์ที่ยังไม่ได้อ่าน โดย moomai »

ขอวิธีแสดงตัวแบ่งหน้าข้อมูลตามข้อมูลที่เรามีหน่อยค่ะ คือตอนนี้แบ่งหน้าได้แล้วแต่มันไ่แบ่งตามข้อมูลที่เรามีค่ะ
Capture.PNG
Capture.PNG (32.57 KiB) Viewed 330 times
เพิ่มเติมด้วยนะคะ คือ
ในส่วนที่ 1 เมื่อคลิกเครื่องหมายในวงกลมต้องไปแสดงข้อมูลที่หน้าแรกแต่อันนี้มันรันหน้าที่ไม่มีข้อมูลค่ะ ต้องแก้ไขยังไงตรงไหนคะ
ในส่วนที่ 2 เมื่อคลิกเครื่องหมายในวงกลมต้องไปแสดงข้อมูลที่หน้าสุดท้านของข้อมูลแต่อันนี้ข้อมูลมีแค่ 6 หน้า ต้องแก้ไขยังไงคะ แล้วถ้าข้อมูลมีมากกว่า 10 ต้องทำยังไงให้มันขึ้นโชว์หน้า ที่มากกว่า 10

โค้ดที่ทำคะ

โค้ด: เลือกทั้งหมด

<?php
require_once 'conn.php';
include '../header.php';

if (isset($_GET['id'])) {
	mysql_query("DELETE FROM tax WHERE id = ".$_GET['id']);
}
$sql = "SELECT * FROM tax ";
$result = mysql_query($sql);
$total = mysql_num_rows($result);
if (isset($_GET['page'])) {
$page = $_GET['page'];
}else{
	$page=1;
}

$start = 0;
if(isset($_GET['page'])){
	$start = ($_GET['page']-1)*10;
}

$sql = "SELECT * FROM tax ORDER BY id desc Limit $start,10";
$result = mysql_query($sql);
?>

<ul class="nav nav-tabs">
     <li role="presentation" ><a href="#"><i class="glyphicon glyphicon-home"></i> Home</a></li>
     <li role="presentation"><a href="#"><i class="glyphicon glyphicon-cog"></i> Tools</a></li>
     <li role="presentation"><a href="index.php"><i class="glyphicon glyphicon-file"></i> Index</a></li> 
     <li role="presentation"><a href="tax.php"><i class="glyphicon glyphicon-edit"></i> Calculation Form</a></li>
     <li role="presentation" class="active"><a href="listtax.php"><i class="glyphicon glyphicon-th-list"></i> Table</a></li>  
</ul>

<div align="center">		
	<h3>ตารางแสดงข้อมูลผู้เข้าใช้งาน</h3>
</div>

<div class="row" align="center">
	<div class="col-md-12">
		<div class="scroll1">
			<table id="table-listtax" class=" table table-striped " >
				<tr>
					<th bgcolor="#8c8cd9"><p align="center">ลำดับ</p></th>
					<th bgcolor="#8c8cd9"><p align="center">ชื่อผู้ใช้งาน</p></th>
					<th bgcolor="#8c8cd9"><p align="right">จำนวนเงิน</p></th>
					<th bgcolor="#8c8cd9"><p align="center">ภาษี %</p></th>
					<th bgcolor="#8c8cd9"><p align="right">เงินภาษี </p></th>
					<th bgcolor="#8c8cd9"><p align="right">จำนวนเงินหลังหักภาษี</p></th>
					<th bgcolor="#8c8cd9"><p align="center">เวลาเข้าใช้งาน</p></th>
					<th bgcolor="#8c8cd9"><p align="center">หมายเลข<br>IP_Address</p></th>		
					<th bgcolor="#8c8cd9"><p align="center">แสดงข้อมูล</p></th>		
				</tr>

				<?php 
					while ($fetch = mysql_fetch_assoc($result)) {
				?>
				<tr>
					<td align="center"><?php echo $fetch['id']; ?></td>
					<td align="center"><?php echo $fetch['name']; ?></td>
					<td align="right"><?php echo number_format($fetch['price'],2); ?></td>
					<td align="center"><?php echo $fetch['tax']; ?></td>
					<td align="right"><?php echo number_format($fetch['vat'],2); ?></td>
					<td align="right"><?php echo number_format($fetch['money'],2); ?></td>
					<td align="center"><?php 
						date_default_timezone_set("Asia/Bangkok");
						echo (date(" Y-m-d / H:i:s  ",$fetch['time'])); ?></td>
					<td align="center"><?php echo $fetch['ip']; ?></td>		
					<td align="center">
						<a href="showtax.php?id=<?php echo $fetch['id']; ?>"><button type="button" class="btn btn-primary">
							<i class="glyphicon glyphicon-new-window"></i></button></a>
					</td>
				</tr>
		
				<?php 
					} 
				?>
			</table>
		</div>
	</div>
</div>


<div class="text-center">	
<nav aria-label="Page navigation">
  <ul class="pagination">
  	<li <?php if ($page == $start) ?>>
  		<a href="listtax.php?page=<?= $page ?>" aria-label="Previous">&laquo;</a>
  	</li>
	<li <?php if ($page == 1) echo 'class="hidden"'; ?>>
	    <a href="listtax.php?page=<?= $page - 1 ?>" aria-label="Previous">
	       	<span aria-hidden="true">&lsaquo;</span>
	    </a>
	</li>

	<?php 
	$pages = ceil($total/10);
	$startpage = ($page > 9) ? $page - 5 : 1;
	$endpage = ($page > 9) ? $page + 10 : $total;
	$endpage = ($endpage > $total) ? $total: 10;
    	for ($i = $startpage; $i <= $endpage; $i++) { ?>
                    <li <?php if ($page == $i) echo 'class="active"'; ?>>
                        <a href="listtax.php?page=<?= $i ?>"><?= $i ?></a></li>
                <?php } ?>


    <li <?php if ($page == $total) echo 'class="hidden"'; ?>>
        <a href="listtax.php?page=<?= $page + 1 ?>" aria-label="Next">
            <span aria-hidden="true">&rsaquo;</span>
        </a>
    </li>

    <li <?php if ($page == $total)  ?>>
        <a href="listtax.php?page=<?= $pages ?>" aria-label="Next">&raquo;</a>
	</li>
  </ul>
</nav>
ทั้งหมด <?php echo "$total";?> รายการ <br><br>
</div>
	
<?php include '../footer.php';?>
The truth is not as elegant as the idea.
ตอบกลับโพส

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 117