|
 |
|
[[ยังทำไม่ได้เลยค่ะ]] อยากให้เมื่อกดปุ่มดูทั้งหมดแล้วโชว์ข้อมูลทั้งหมด จากที่โชว์แค่ 10 table ต่อจาก table ที่โชว์ลงมาเลย |
|
 |
|
|
 |
 |
|
Code (PHP)
<table>
<?php do { ?>
<tr>
<td width="80%"><a href="<?PHP echo empty($row_postrcs['post_file']) ? $row_postrcs['post_link'] : 'file/'.$row_postrcs['post_file']; ?>"><?php echo $row_postrcs['post_text']; ?>
</a>
</td>
<td width="11%">
<div align="center"><a onclick="MM_openBrWindow('update-post.php?postid=<?php echo $row_postrcs['id']; ?>','editpost','scrollbars=yes,resizable=yes,width=600,height=200')"><button class="button button4">แก้ไข</button></a></div>
</td>
<td width="9%">
<div align="center"><a href="delete-post.php?id=<?php echo $row_postrcs['id']; ?>"><button class="button button3">ลบ</button></a></div>
</td>
</tr>
<?php } while ($row_postrcs = mysql_fetch_assoc($postrcs)); ?>
</table><br />
<button class="button button5">ดูทั้งหมด</button>
นี้เป็นโค้ดส่วนที่โชว์และปุ่มดูทั้งหมด
Code (PHP)
$maxRows_postrcs = 10;
$pageNum_postrcs = 0;
if (isset($_GET['pageNum_postrcs'])) {
$pageNum_postrcs = $_GET['pageNum_postrcs'];
}
$startRow_postrcs = $pageNum_postrcs * $maxRows_postrcs;
mysql_select_db($database_myconnection, $myconnection);
$query_postrcs = "SELECT * FROM post ORDER BY id DESC";
$query_limit_postrcs = sprintf("%s LIMIT %d, %d", $query_postrcs, $startRow_postrcs, $maxRows_postrcs);
$postrcs = mysql_query($query_limit_postrcs, $myconnection) or die(mysql_error());
$row_postrcs = mysql_fetch_assoc($postrcs);
if (isset($_GET['totalRows_postrcs'])) {
$totalRows_postrcs = $_GET['totalRows_postrcs'];
} else {
$all_postrcs = mysql_query($query_postrcs);
$totalRows_postrcs = mysql_num_rows($all_postrcs);
}
$totalPages_postrcs = ceil($totalRows_postrcs/$maxRows_postrcs)-1;
นี้เป็นโค้ดคำสั่งโชว์ค่ะ
รบกวนผู้รู้ทีนะค่ะ เป็นมือใหม่ php ค่ะ
Tag : PHP, MySQL, HTML, CSS, HTML5, JavaScript

|
ประวัติการแก้ไข 2018-09-18 14:16:06
|
 |
 |
 |
 |
Date :
2018-09-14 10:21:52 |
By :
ampere27 |
View :
678 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าไม่ใช้ Ajax ช่วย หาวิธีสร้างตัวแปร เก็บค่า $maxRows_postrcs = 10; เวลากดก็ + ค่าให้กับ $maxRows_postrcs แต่ถ้าจะให้ง่ายเลยก็แยกไฟล์ไปเป็นอีกไฟล์ครับ กดดูทั้งหมด ก็ link ไปอีกไฟล์ แล้วไม่ต้องกำหนด Limit ข้อมูล select * ไปเลยครับ 
|
 |
 |
 |
 |
Date :
2018-09-14 13:23:25 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าขอให้ทำเป็นโค้ดให้เลยได้มั้ยค่ะ พอดีเป็นมือใหม่ โค้ดที่ใช้ก็เป็นโค้ดสำเร็จรูปจากโปรแกรมไม่ได้เขียนเองทั้งหมดค่ะ ถ้าสามารถช่วยได้รบกวนอีกทีนะค่ะ
ส่วนคำแนะนำที่ให้ลิ้งไปหน้าใหม่ ตอนแรกก็ทำไว้แล้วค่ะ เพียงแต่อยากให้มันดูแอดวานซ์ขึ้นมาหน่อย เผื่อจะมีคนช่วยได้ค่ะ รบกวนทีนะค่ะ
|
 |
 |
 |
 |
Date :
2018-09-14 14:01:08 |
By :
ampere27 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php
$maxRows_postrcs = 10;
$sql = "SELECT * FROM post ORDER BY id DESC";
// ส่วน query ข้อมูล
if (! empty($_GET['pageNum_postrcs'])) {
$pageNum_postrcs = (int)$_GET['pageNum_postrcs'];
$offset = ($pageNum_postrcs > 1) ? ($pageNum_postrcs-1)*$maxRows_postrcs : 0;
$sql .= " LIMIT {$offset}, {$maxRows_postrcs}";
}
$postrcs = mysql_query($sql, $myconnection) or die(mysql_error());
....
....
....
?>
// ส่วน pagination
<a href="posts.php" class="button button5">ดูทั้งหมด</a>
<?php for ($i = 1; $i <= $totalPages_postrcs; $i++) : ?>
<a href="posts.php?pageNum_postrcs=<?php echo $i; ?>" class="button button5"><?php echo $i; ?></a>
<?php endfor; ?>
|
 |
 |
 |
 |
Date :
2018-09-15 12:14:34 |
By :
chayayol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

อยากให้กดดูทั้งหมดแล้วข้อมูลโผล่ลงมาจากตารางนี้เลยค่ะ แบบต่อลงมาให้แสดงทั้งหมดในฐานข้อมูล
|
 |
 |
 |
 |
Date :
2018-09-17 10:18:13 |
By :
ampere27 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|