|
![](/images/resource/spacer.gif) |
|
สอบถามหน่อยค่ะ เกี่ยวกับรับค่า Checkbox ที่เป็น array แล้วมาแสดงผลไม่ได้ กับเรื่องฟ้องการคลิ๊กจำนวน checkbox ค่ะ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (JavaScript)
<script>
var checkbox_count=0; // ตัวนับ check
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==2){
alert('เลือกได้ไม่เกิน 2'); chk.checked=false;
}else checkbox_count++;
}else checkbox_count--;
}
</script>
<input type="checkbox" name="product_id[]" value="<?=$r["product_id"];?>" onclick="sum_check( this )">
ลองแบบนี้ดูไหมครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-20 15:41:28 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
<input type="checkbox" onclick="return check()" name="product_id[]" value="<?=$r["product_id"];?>">
ใช้ jquery นะ
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
Code (PHP)
<script>
function check(){
if ( $('input[name="product_id[]"]:checked').length > 2){
alert('เกิน');
return false;
}
}
</script>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-20 15:46:27 |
By :
gaowteen |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ได้แล้วค่ะ นับจำนวนคลิ๊ก ไม่เกิน 2 ตามคุณ Chaidhanan ได้แล้วค่ะ ขอบคุณค่ะ Chaidhanan ค่ะ ^___^
แต่ขอรบกวนสอบถามเรื่อง รับค่าจาก array ที่เลือกมาแสดง หน่อยได้ใหมค่ะ ยังไม่ออกตรงกับค่าที่กดเลือกมาเลยค่ะ T___T
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-20 15:49:05 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (PHP)
<?php include 'connect.php';
$in_value = implode(',' , $_POST['product_id']);
$sql = mysql_query("SELECT * FROM tb_product where product_id in ($in_value)");
?>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div><a href="1.php">ย้อนกลับ</a><br/><br/></div>
<?php
while( $r = mysql_fetch_assoc($sql) ){
echo "<div style='float:left; width:200px;'>";
echo "รหัส ".$r["product_id"]."<br/>";
echo "ชื่อสินค้า ".$r["product_name"]."<br/>";
echo "ขนาด ".$r["product_size"]."<br/>";
echo "</div>";
}
?>
</body>
</html>
ปล.แก้ไข พิมพ์ตก where ไปครับ
|
ประวัติการแก้ไข 2014-10-20 15:57:06 2014-10-20 15:57:30
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-20 15:52:35 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองทำตาม คุณ Chaidhanan แล้วค่ะ
ขึ้นฟ้องว่า Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\test\compare\2.php on line 13
อันนี้อะค่ะ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-20 16:09:37 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
$sql = mysql_query("SELECT * FROM tb_product where product_id in ($in_value)");
ตรงนี้ไม่รู้ ว่าได้เพิ่ม where เข้าไปหรือยังอะครับ คือว่าผม พิมพ์ตกไปครั้งแรกอะครับ แต่แก้ไขแล้ว
แต่บังเอิญไม่รู้ว่า ก๊อปไปเป็นของเก่า หรือแก้ไขแล้ว
|
ประวัติการแก้ไข 2014-10-20 16:13:33
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-20 16:13:10 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ได้แล้วค่ะ ตามที่คุณ Chaidhanan แนะนำเลยค่ะ ขอบคุณมากๆๆๆๆนะค่ะ งง ตั้งนานกว่าจะแก้ได้ @^_________^@
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-20 16:48:51 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
สอบถามเพิ่มเติมอีกนิดนะค่ะ พอดีว่าเพิ่มโคดเลขหน้า กับเพิ่มเมนูเลือกประเภทสินค้าไปด้วยค่ะ พอคลิ๊ก Checkbox แล้วเปลี่ยนไปหน้าอื่น ค่า Checkbox มันไม่คงไว้ค่ะ อยากทราบว่า ถ้าต้องการให้ค่า check มันคงค่าเดิมไว้ หากเปลี่ยนไปหน้าอื่น ไม่ทราบว่า ต้องเพิ่มตรงใหนค่ะ รบกวนด้วยนะค่ะ ขอคำชี้แนะด้วยค่ะ ขอบคุณนะค่ะ
![error checkbox error checkbox](https://www.thaicreate.com/upload/stock/20141021110216.jpg?v=1001)
Code (PHP)
<?php
session_start();
//---------------//
include_once "connect.php";
include_once "function/paging.php";
$sql = "select * from tb_product Where category_id = $_GET[category_id]";
$rs = mysql_query($sql);
if( $_GET[category_id]!=''){;
//--------------- แบ่งหน้า -------------------//
$Num_Rows = mysql_num_rows($rs);
$Per_Page = 10; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$sql .=" order by product_id DESC LIMIT $Page_Start , $Per_Page";
$rs = mysql_query($sql);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Check ห้ามเลือกเกิน 2 -->
<script>
var checkbox_count=0; // ตัวนับ check
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==3){
alert('เลือกได้ไม่เกิน 3'); chk.checked=false;
}else checkbox_count++;
}else checkbox_count--;
}
</script>
<!-- Check ค่าว่าง -->
<script language="javascript">
function check(frm) {
var inputs = frm.getElementsByTagName('input');
for(var i = 0 ; i < inputs.length ; i++){
input = inputs[i];
if(input.type == 'checkbox'){
if (input.checked){
return true;
};
};
};
alert('กรุณาเลือกอย่างน้อย 1 รายการ');
return false;
}
</script>
<!-- End Check ค่าว่าง -->
</head>
<body>
<a href="1.php?category_id=1">กำจัดแมลง</a> <a href="1.php?category_id=29">กำจัดปลวก</a> <a href="1.php?category_id=2">ทำความสะอาด</a>
<form action="2.php" method="post" name="compare" id="compare" onSubmit="return check(this)">
Please select Product.<br>
<?php if(!empty($rs)): ?>
<?php while ($r = mysql_fetch_assoc($rs)): ?>
<?php if($_GET[category_id]!=''){?>
<input type="checkbox" name="product_id[]" value="<?=$r["product_id"];?>" onclick="sum_check( this )">
รหัส <?=$r["product_id"];?> ชื่อสินค้า <?=$r["product_name"];?> ขนาด<?=$r["product_size"];?><br>
<?php }?>
<?php endwhile ?>
<?php endif ?>
<input name="btnSubmit" type="submit" value="Submit">
</form>
<!-------- แสดงแบ่งหน้า ---------->
<?php if($_GET[category_id]!=''){;?>
<div class="clear"></div>
<div class="paging_space">
<?
$pages = new Paginator;
$pages->items_total = $Num_Rows;
$pages->mid_range = 10;
$pages->current_page = $Page;
$pages->default_ipp = $Per_Page;
$pages->url_next = "1.php?category_id=$_GET[category_id]&QueryString=value&Page=";
$pages->paginate();
echo $pages->display_pages()
?>
</div>
<?php }?>
<!------- End แสดงแบ่งหน้า ------->
</body>
</html>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 11:04:38 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
เอา class paginator มาดูหน่อยครับ
หรือ จะ วิวซอร์ส มาดูก็ได้นะครับ มันเป็น ตลาส ผมไม่รู้ว่า มัน ส่งอะไรออกมา
มันเป็นส่วน PHP Generating ซึ่งสมบูรณ์แล้ว ซึ่งจะแกไขตรงๆ ไม่ได้จาก javascript ถ้าไม่เห็นหน้าตาครับ
คือผมไม่รู้ว่าสร้างเป็น tag a หรือ <p onclick หรือ <b onclick นะครับ มันทำได้หลายรูปแบบ จะแก้ต้องรู้ตรงนี้ครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 11:24:50 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
View Source ออกมาได้แบบนี้ค่ะ
View Source
Code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Check ห้ามเลือกเกิน 2 -->
<script>
var checkbox_count=0; // ตัวนับ check
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==3){
alert('เลือกได้ไม่เกิน 3'); chk.checked=false;
}else checkbox_count++;
}else checkbox_count--;
}
</script>
<!-- Check ค่าว่าง -->
<script language="javascript">
function check(frm) {
var inputs = frm.getElementsByTagName('input');
for(var i = 0 ; i < inputs.length ; i++){
input = inputs[i];
if(input.type == 'checkbox'){
if (input.checked){
return true;
};
};
};
alert('กรุณาเลือกอย่างน้อย 1 รายการ');
return false;
}
</script>
<!-- End Check ค่าว่าง -->
</head>
<body>
<a href="1.php?category_id=1">กำจัดแมลง</a> <a href="1.php?category_id=29">กำจัดปลวก</a> <a href="1.php?category_id=2">ทำความสะอาด</a>
<form action="2.php" method="post" name="compare" id="compare" onSubmit="return check(this)">
Please select Product.<br>
<input type="checkbox" name="product_id[]" value="96" onclick="sum_check( this )">
รหัส 96 ชื่อสินค้า เชอร์วู้ด เอาท์ดอร์ ชิลด์ ขนาด<br>
<input type="checkbox" name="product_id[]" value="94" onclick="sum_check( this )">
รหัส 94 ชื่อสินค้า เชนไดร้ท์ สเตดฟาส 40 อีซี ขนาด<br>
<input type="checkbox" name="product_id[]" value="86" onclick="sum_check( this )">
รหัส 86 ชื่อสินค้า ฟลอราลิส ขนาด<br>
<input type="checkbox" name="product_id[]" value="63" onclick="sum_check( this )">
รหัส 63 ชื่อสินค้า ไซเปอร์แทค 15 เอ็มซี ขนาด<br>
<input type="checkbox" name="product_id[]" value="62" onclick="sum_check( this )">
รหัส 62 ชื่อสินค้า เชนไดร้ท์ 2 กลิ่นลาเวนเดอร์ ขนาด<br>
<input type="checkbox" name="product_id[]" value="61" onclick="sum_check( this )">
รหัส 61 ชื่อสินค้า เชนไดร้ท์ สูตรน้ำ ขนาด<br>
<input type="checkbox" name="product_id[]" value="60" onclick="sum_check( this )">
รหัส 60 ชื่อสินค้า เชนไดร้ท์ 3 ขนาด<br>
<input type="checkbox" name="product_id[]" value="59" onclick="sum_check( this )">
รหัส 59 ชื่อสินค้า เชนไดร้ท์ 2 ขนาด<br>
<input type="checkbox" name="product_id[]" value="29" onclick="sum_check( this )">
รหัส 29 ชื่อสินค้า เชนไดร้ท์ เพาเดอร์ ขนาด500 g<br>
<input type="checkbox" name="product_id[]" value="28" onclick="sum_check( this )">
รหัส 28 ชื่อสินค้า พรีแม็กซ์ อิมิฟอร์ซ 50 เอสซี ขนาด500 cc<br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
<!-------- แสดงแบ่งหน้า ---------->
<div class="clear"></div>
<div class="paging_space">
<a class="current" href="#">1</a> <a class="paginate" href="1.php?category_id=1&QueryString=value&Page=2">2</a> </div>
<!------- End แสดงแบ่งหน้า ------->
</body>
</html>
-------------------------------------------------------------------------------------------
ส่วน class Paginator
Code (PHP) class Paginator
<?
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp;
var $querystring;
var $url_next;
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 7;
$this->items_per_page = $this->default_ipp;
$this->url_next = $this->url_next;
}
function paginate()
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($this->num_pages > 10)
{
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"".$this->url_next.$this->$prev_page."\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['Page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"".$this->url_next.$i."\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['Page'] != 'All')) ? "<a class=\"paginate\" href=\"".$this->url_next.$next_page."\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"".$this->url_next.$i."\">$i</a> ";
}
}
$this->low = ($this->current_page-1) * $this->items_per_page;
$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_pages()
{
return $this->return;
}
}
?>
-------------------------------------------------------------------------------------------
ขอบคุณนะคะ ^___^
|
ประวัติการแก้ไข 2014-10-21 11:39:58
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 11:39:15 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ต้องเพิ่ม javascript ในหน้า HTML เพิ่ม
Code (JavaScript)
var checkbox_count=0; // ตัวนับ check
var check_list = '';
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==3){
alert('เลือกได้ไม่เกิน 3'); chk.checked=false;
}else{
checkbox_count++;
check_list +='['+chk.value+']';
}
}else {
checkbox_count--;
check_list = eval('check_list.replace(/\\['+chk.value+'\\]/, "")');
}
}
function change_page( page ){
// script รองรับ คำสั่ง จาก paginator
location.href ="1.php?category_id=<?php echo $_GET['category_id'];?>&QueryString=value&Page="+page;
}
และแก้ไข paginator เพิ่มเติม
Code (PHP)
<?
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp;
var $querystring;
var $url_next;
function Paginator(){
$this->current_page = 1;
$this->mid_range = 7;
$this->items_per_page = $this->default_ipp;
$this->url_next = $this->url_next;
}
function paginate(){
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($this->num_pages > 10)
{
/*
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ?
"<a class=\"paginate\" href=\"".$this->url_next.$this->$prev_page."\">« Previous</a> "
:
"<span class=\"inactive\" href=\"#\">« Previous</span> ";
แก้ คำสั่งนี้ครับ เป็น บันทัดล่าง
*/
/////////////////////////////////////////////////////////////////////////////////////
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ?
"<a class='paginate' href='javascript: change_page( $this->$prev_page )'>« Previous</a> "
:
"<span class='inactive' >« Previous</span> ";
////////////////////////////////////////////////////////////////////////////////////
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
/*
$this->return .= ($i == $this->current_page And $_GET['Page'] != 'All') ?
"<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> "
:
"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"".$this->url_next.$i."\">$i</a> ";
*/
////////////////////////////////////////////////////////////////////////////////
$this->return .= ($i == $this->current_page And $_GET['Page'] != 'All') ?
"<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> "
:
"<a class='paginate' title='Go to page $i of $this->num_pages' href='javascript: change_page( $i )' >$i</a> ";
////////////////////////////////////////////////////////////////////////////////
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
/*
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['Page'] != 'All')) ?
"<a class=\"paginate\" href=\"".$this->url_next.$next_page."\">Next »</a>\n"
:
"<span class=\"inactive\" href=\"#\">» Next</span>\n";
*/
////////////////////////////////////////////////////////////////////////////////
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['Page'] != 'All')) ?
"<a class='paginate' href='javascript: change_page( $next_page )' >Next »</a>\n"
:
"<span class='inactive' >» Next</span>\n";
////////////////////////////////////////////////////////////////////////////////
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
/*
$this->return .= ($i == $this->current_page) ?
"<a class=\"current\" href=\"#\">$i</a> "
:
"<a class=\"paginate\" href=\"".$this->url_next.$i."\">$i</a> ";
*/
//////////////////////////////////////////////////////////////////////////////
$this->return .= ($i == $this->current_page) ?
"<a class='current' >$i</a> "
:
"<a class='paginate' href='javascript: chage_page($i)' >$i</a>";
//////////////////////////////////////////////////////////////////////////////
}
}
$this->low = ($this->current_page-1) * $this->items_per_page;
$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_pages()
{
return $this->return;
}
}
?>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 12:13:20 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
แปปนะครับ ลืม โค๊ด เพิ่ม checkbox 55555
Code (JavaScript)
var checkbox_count=0; // ตัวนับ check
var check_list = '<?=(isset($_REQUEST['chkbox']) ? '['.implode('][', $_REQUEST['chkbox']).']' : '')?>';
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==3){
alert('เลือกได้ไม่เกิน 3'); chk.checked=false;
}else{
checkbox_count++;
check_list +='['+chk.value+']';
}
}else {
checkbox_count--;
check_list = eval('check_list.replace(/\\['+chk.value+'\\]/, "")');
}
}
function change_page( page ){
// script รองรับ คำสั่ง จาก paginator
var chk = check_list.replace(/\]\[/, ',').replace(/\[|\]/, '').split(',');
location.href="1.php?category_id=<?=$_GET['category_id']?>&QueryString=value"+
"&Page="+page+(chk.length? '&chkbox='+chk : '');
}
Code (PHP)
<?php while ($r = mysql_fetch_assoc($rs)): ?>
<?php if($_GET[category_id]!=''){
// เพิ่มบันทัดล่าง และเพิ่ม <?=$chk?> ใน input type=checkbox
$chk=isset($_REQUEST['chkbox'])? (in_array($r['product_id'], $_REQUEST['chkbox'])? 'checked' : '') : '';
?>
<input type="checkbox" name="product_id[]" value="<?=$r["product_id"];?>"
onclick="sum_check( this )" <?=$chk?> >
รหัส <?=$r["product_id"];?> ชื่อสินค้า <?=$r["product_name"];?> ขนาด<?=$r["product_size"];?><br>
<?php }?>
<?php endwhile ?>
|
ประวัติการแก้ไข 2014-10-21 12:35:39 2014-10-21 12:38:51 2014-10-21 12:39:49 2014-10-21 12:42:46 2014-10-21 12:44:07
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 12:14:42 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองดูตามคุณ Chaidhanan แล้วค่ะ กดเปลี่ยนหน้าไม่ได้อะค่ะ แต่ทำลิ้งให้นะค่ะ และพอลองกดเลือก checkbox ของกำจัดแมลง พอลองไปเปลี่ยนเป็นกำจัดปลวก checkbox ก็ไม่ค้าง checkbox ให้ค่ะ มันเป็นเพราะอะไรหรือค่ะ งง ค่ะ T^T รบกวนแนะนำหน่อยนะค่ะ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 13:37:12 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
รบกวน ขอวิวซอร์ส มาดูอีกทีนะครับ หลังจากแก้ไขแล้ว
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 13:42:51 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
View Source ได้มาแบบนี้ค่ะ รบกวนแนะนำด้วยนะค่ะ ^_^
View Source
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Check ห้ามเลือกเกิน 2 -->
<script>
var checkbox_count=0; // ตัวนับ check
var check_list = '';
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==3){
alert('เลือกได้ไม่เกิน 3'); chk.checked=false;
}else{
checkbox_count++;
check_list +='['+chk.value+']';
}
}else {
checkbox_count--;
check_list = eval('check_list.replace(/\\['+chk.value+'\\]/, "")');
}
}
function change_page( page ){
// script รองรับ คำสั่ง จาก paginator
var chk = check_list.replace(/\]\[/, ',').replace(/\[|\]/, '').split(',');
location.href="1.php?category_id=1&QueryString=value"+
"&Page="+page+(chk.length? '&chkbox='+chk : '');
}
</script>
<!-- Check ค่าว่าง -->
<script language="javascript">
function check(frm) {
var inputs = frm.getElementsByTagName('input');
for(var i = 0 ; i < inputs.length ; i++){
input = inputs[i];
if(input.type == 'checkbox'){
if (input.checked){
return true;
};
};
};
alert('กรุณาเลือกอย่างน้อย 1 รายการ');
return false;
}
</script>
<!-- End Check ค่าว่าง -->
</head>
<body>
<a href="1.php?category_id=1">กำจัดแมลง</a> <a href="1.php?category_id=29">กำจัดปลวก</a> <a href="1.php?category_id=2">ทำความสะอาด</a>
<form action="2.php" method="post" name="compare" id="compare" onSubmit="return check(this)">
Please select Product.<br>
<input type="checkbox" name="product_id[]" value="96"
onclick="sum_check( this )" >
รหัส 96 ชื่อสินค้า เชอร์วู้ด เอาท์ดอร์ ชิลด์ ขนาด<br>
<input type="checkbox" name="product_id[]" value="94"
onclick="sum_check( this )" >
รหัส 94 ชื่อสินค้า เชนไดร้ท์ สเตดฟาส 40 อีซี ขนาด<br>
<input type="checkbox" name="product_id[]" value="86"
onclick="sum_check( this )" >
รหัส 86 ชื่อสินค้า ฟลอราลิส ขนาด<br>
<input type="checkbox" name="product_id[]" value="63"
onclick="sum_check( this )" >
รหัส 63 ชื่อสินค้า ไซเปอร์แทค 15 เอ็มซี ขนาด<br>
<input type="checkbox" name="product_id[]" value="62"
onclick="sum_check( this )" >
รหัส 62 ชื่อสินค้า เชนไดร้ท์ 2 กลิ่นลาเวนเดอร์ ขนาด<br>
<input type="checkbox" name="product_id[]" value="61"
onclick="sum_check( this )" >
รหัส 61 ชื่อสินค้า เชนไดร้ท์ สูตรน้ำ ขนาด<br>
<input type="checkbox" name="product_id[]" value="60"
onclick="sum_check( this )" >
รหัส 60 ชื่อสินค้า เชนไดร้ท์ 3 ขนาด<br>
<input type="checkbox" name="product_id[]" value="59"
onclick="sum_check( this )" >
รหัส 59 ชื่อสินค้า เชนไดร้ท์ 2 ขนาด<br>
<input type="checkbox" name="product_id[]" value="29"
onclick="sum_check( this )" >
รหัส 29 ชื่อสินค้า เชนไดร้ท์ เพาเดอร์ ขนาด500 g<br>
<input type="checkbox" name="product_id[]" value="28"
onclick="sum_check( this )" >
รหัส 28 ชื่อสินค้า พรีแม็กซ์ อิมิฟอร์ซ 50 เอสซี ขนาด500 cc<br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
<!-------- แสดงแบ่งหน้า ---------->
<div class="clear"></div>
<div class="paging_space">
<a class='current' >1</a> <a class='paginate' href='javascript: chage_page(2)' >2</a> </div>
<!------- End แสดงแบ่งหน้า ------->
</body>
</html>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 13:57:16 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
<a class='current' >1</a> <a class='paginate' href='javascript: chage_page(2)' >2</a></div>
ขอโทษครับ พิมพ์ตกไปอะครับ
chage_page
ต้องเป็น
change_page
รบกวนเข้าไปหา chage_page ใน paginator แล้วแก้เป็น change_page อะครับ บันทัดที่ 110
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 14:04:17 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
แก้แล้วค่ะ พอกดหน้า 2 มันขึ้น error แบบนี้ค่ะ แล้วพอกดหน้าหนึ่งไม่ได้ค่ะ T^T
![error checkbox1 error checkbox1](https://www.thaicreate.com/upload/stock/20141021142246.jpg?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 14:23:32 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (JavaScript)
function change_page( page ){
// script รองรับ คำสั่ง จาก paginator
var chk = check_list>''? ( check_list.replace(/\]\[/g, ',').replace(/\[|\]/g, '').split(',')) : Array();
alert(page);
location.href="t.php?category_id=1&QueryString=value"+
"&Page="+page+(chk.length>0? '&chkbox='+chk : '');
}
เอาฟังก์ชั่นนี้เข้าไปแทนที่ครับ
คือตอนแรก เห็นกำหนดไว้แค่ 2 รายการอะครับ เลยไม่ได้ใส่ parameter การเสริช glogal ไว้
ตอนนี้ เพิ่ม g หลัง replace(//g) ให้แล้วนะครับ ซึ่งเป็นการให้ทำทั้งหมด ตอนนี้จะกำหนด กี่รายการ ก็ได้แล้วครับ
เพิ่มอันนี้ด้วยครับ
Code (PHP)
<?php
/////////////////////////////////////////////////////////////// เพิ่มบันทัดข้างล่าง
$chk_arr=isset($_REQUEST['chkbox']) ? explode(',', $_REQUEST['chkbox']) : array();
///////////////////////////////////////////////////////////////
while ($r = mysql_fetch_assoc($rs)): ?>
<?php if($_GET[category_id]!=''){
/////////////////////////////////////////////////////////////// แก้บันทัดข้างล่าง
$chk=in_array($r['product_id'], $chk_arr)? 'checked' : '';
///////////////////////////////////////////////////////////////
?>
<input type="checkbox" name="product_id[]" value="<?=$r["product_id"];?>"
onclick="sum_check( this )" <?=$chk?> >
รหัส <?=$r["product_id"];?> ชื่อสินค้า <?=$r["product_name"];?> ขนาด<?=$r["product_size"];?><br>
<?php }?>
<?php endwhile ?>
|
ประวัติการแก้ไข 2014-10-21 14:46:42 2014-10-21 14:47:08 2014-10-21 14:59:05
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 14:38:59 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
-
|
ประวัติการแก้ไข 2014-10-21 15:04:24
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 15:01:19 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ดูส่วนที่แก้ไขเพิ่มหรือยังครับ สงสัยจะก๊อปเร็วไปหน่อย
ขอโทษด้วยนะครับ แบบชักเบลอๆ หลงโน่นลืมนี่อะครับตามประสาคนเริ่มแก่แล้ว 5555
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 15:06:44 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
พึ่งมาเห็นส่วนที่แก้ไขเพิ่มเติมค่ะ อิอิ ก๊อบปี้เร็วไป พอดีทำไปด้วยแก้ไปด้วย ลองแก้ไขแล้วนะค่ะ ไม่ขึ้น error แบบเดิมแล้วค่ะ
แต่เจอว่าแบบนี้มาแทนค่ะ (ทำเป็นรูปมานะค่ะ กลัวเขียนแล้วงง อิอิ) คือถ้าเลือก Checkbox หน้าแรก หน้าสองจะกลับไป checkbox ของเก่าไม่ได้ค่ะ แต่ถ้าเลือก Checkbox หน้าสอง เมื่อกด submit จะได้แค่ค่าของหน้าสองมาแทนค่ะ
![error ck3 error ck3](https://www.thaicreate.com/upload/stock/20141021152604.jpg?v=1001)
หน้าตอนเลือกประเภทก็เหมือนกันค่ะ ถ้าเลือกประเภทหนึ่ง แล้วไปเลือกอีกประเภทหนึง ค่ามันจะหายไปทั้งสองเลยค่ะ เหมือนไม่เก็บค่า ไว้ แบบนี้ต้องแก้ยังไงบ้างค่ะ รบกวนด้วยนะค่ะ จนปัญญาจริงๆค่ะ งง มาก ไม่รู้จะเขียนยังไงจริงๆค่ะ ขอบคุณมากๆนะค่ะ ที่ช่วยดูให้นะค่ะ
![error ck4 error ck4](https://www.thaicreate.com/upload/stock/20141021152650.jpg?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-21 15:29:10 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
เมื่อวานนั่งแก้โค๊ดแล้วลืมเซฟ เลยพักยาว
ลองดูนะครับ อันนี้ผมเอาโค๊ดมาปรับปรุงเพิ่มเติม
Code (PHP)
<?php
session_start();
if(!isset($_GET['category_id'])) {
header('location: index.php');
// ตรวจสอบการส่งค่า ถ้าไม่มีตามกำหนด ให้ไปเริ่มที่ index.php
}
//---------------//
include_once "connect.php"; // ถ้าเปลี่ยนเป็น mysqli ก็จะดีนะครับเพราะ เวอร์ชั่นใหม่ๆ จะไม่มี mysql แล้วครับ
include_once "function/paging.php";
$Per_Page = 10; // Per Page
$sql = "select count(*) from tb_product Where category_id = $_GET[category_id]"; // คิวรี่เฉพาะส่วนที่ต้องการ จำนวน rows
$rs = mysql_query($sql); list($Num_Rows) = mysql_fetch_row($rs); mysql_free_result($rs);
$Num_Pages = ceil($Num_Rows / $Per_Page);
$Page = isset($_GET["Page"])? $_GET["Page"] : 1;
$sql = 'select * from tb_product Where category_id = '.$_GET['category_id'];
$sql .=' order by product_id DESC LIMIT '.(($Page -1) * $Per_Page).' , ' . $Per_Page;
$rs = mysql_query($sql);
$chk_arr=isset($_GET['checkbox'])? explode(',', $_GET['checkbox']) : array();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Check ห้ามเลือกเกิน 2 -->
<script>
var checkbox_count=<?=count($chk_arr)?>; // ตัวนับ check
var check_list ='<?=(count($chk_arr)? '['.implode('][', $chk_arr).']' : '')?>';
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==3){ alert('เลือกได้ไม่เกิน 3'); chk.checked=false;
}else{ checkbox_count++; check_list +='['+chk.value+']'; }
}else { checkbox_count--; check_list = eval('check_list.replace(/\\['+chk.value+'\\]/, "")'); }
}
function chk_text(){
var a = check_list>''? ( check_list.replace(/\]\[/g, ',').replace(/\[|\]/g, '').split(',')) : Array();
return (a.length? '&chkbox='+a : '');
}
function change_page( page ){ location.href="1.php?category_id=<?=$_GET['category_id']?>&Page="+page+chk_text(); }
function change_cate( cate_id ){ location.href='1.php?category_id='+cate_id+chk_text(); }
function check() {
if(checkbox_count) return true; alert('กรุณาเลือกอย่างน้อย 1 รายการ'); return false;
}
</script>
</head>
<body>
<a href="javascript: change_cate(1)">กำจัดแมลง</a>
<a href="javascript: change_cate(29)">กำจัดปลวก</a>
<a href="javascript: change_cate(2)">ทำความสะอาด</a>
<form action="2.php" method="post" name="compare" id="compare" onSubmit="return check()">
Please select Product.<br>
<?php while ($r = mysql_fetch_assoc($rs)): ?>
<input type="checkbox" name="product_id[]" value="<?=$r["product_id"];?>" onclick="sum_check( this )">
รหัส <?=$r["product_id"];?> ชื่อสินค้า <?=$r["product_name"];?> ขนาด<?=$r["product_size"];?><br>
<?php endwhile ?>
<input name="btnSubmit" type="submit" value="Submit">
</form>
<div class="clear"></div>
<div class="paging_space">
<?php
$pages = new Paginator;
$pages->items_total = $Num_Rows;
$pages->mid_range = 10;
$pages->current_page = $Page;
$pages->default_ipp = $Per_Page;
$pages->paginate();
echo $pages->display_pages()
?>
</div>
</body>
</html>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 10:06:41 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ขอบคุณมากๆค่ะ @^____^@ เดี๋ยวลองดูก่อนนะค่ะ คุณ Chaidhanan
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 13:45:58 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองดูตามคุณ Chaidhanan แล้วค่ะ ค่า Checkbox ไม่คงค่าไว้ หากเปลี่ยนเป็นหน้าอื่นหรือสินค้าประเภทอื่นอะค่ะ T^T
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 14:59:03 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
บันทัด 54-55 เอาส่วนนี้ไปแทนทีด้วยนะครับ
Code (PHP)
<?php
while ($r = mysql_fetch_assoc($rs)){
$chk=in_array( $r['product_id'], $chk_arr)? 'checked' : '';
?>
<input type="checkbox" name="product_id[]" value="<?=$r["product_id"];?>" onclick="sum_check( this )" <?=$chk?>>
ช่วยวิวซอร์สมาดูด้วยนะครับ
Code (JavaScript)
<script>
var checkbox_count=<?=count($chk_arr)?>; // ตัวนับ check
var check_list ='<?=(count($chk_arr)? '['.implode('][', $chk_arr).']' : '')?>';
อยากเห็น วิวซอร์สข้างบนน่ะครับ
ปล.ตัว check_list เป็นตัวเก็บค่า checkbox ที่กดน่ะครับ
|
ประวัติการแก้ไข 2014-10-22 15:14:16
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 15:13:17 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองเปลี่ยนตามที่คุณ Chaidhanan แล้วค่ะ ค่ายังไม่คงที่เหมือนเดิมค่ะ T^T ลองวิวซอสออกมาได้ค่าแบบนี้ค่ะ
View Source
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Check ห้ามเลือกเกิน 2 -->
<script>
var checkbox_count=0; // ตัวนับ check
var check_list ='';
function sum_check( chk ){
if(chk.checked){
if(checkbox_count==3){ alert('เลือกได้ไม่เกิน 3'); chk.checked=false;
}else{ checkbox_count++; check_list +='['+chk.value+']'; }
}else { checkbox_count--; check_list = eval('check_list.replace(/\\['+chk.value+'\\]/, "")'); }
}
function chk_text(){
var a = check_list>''? ( check_list.replace(/\]\[/g, ',').replace(/\[|\]/g, '').split(',')) : Array();
return (a.length? '&chkbox='+a : '');
}
function change_page( page ){ location.href="1.php?category_id=1&Page="+page+chk_text(); }
function change_cate( cate_id ){ location.href='1.php?category_id='+cate_id+chk_text(); }
function check() {
if(checkbox_count) return true; alert('กรุณาเลือกอย่างน้อย 1 รายการ'); return false;
}
</script>
</head>
<body>
<a href="javascript: change_cate(1)">กำจัดแมลง</a>
<a href="javascript: change_cate(29)">กำจัดปลวก</a>
<a href="javascript: change_cate(2)">ทำความสะอาด</a>
<form action="2.php" method="post" name="compare" id="compare" onSubmit="return check()">
Please select Product.<br>
<input type="checkbox" name="product_id[]" value="96" onclick="sum_check( this )" >
รหัส 96 ชื่อสินค้า เชอร์วู้ด เอาท์ดอร์ ชิลด์ ขนาด<br>
<input type="checkbox" name="product_id[]" value="94" onclick="sum_check( this )" >
รหัส 94 ชื่อสินค้า เชนไดร้ท์ สเตดฟาส 40 อีซี ขนาด<br>
<input type="checkbox" name="product_id[]" value="86" onclick="sum_check( this )" >
รหัส 86 ชื่อสินค้า ฟลอราลิส ขนาด<br>
<input type="checkbox" name="product_id[]" value="63" onclick="sum_check( this )" >
รหัส 63 ชื่อสินค้า ไซเปอร์แทค 15 เอ็มซี ขนาด<br>
<input type="checkbox" name="product_id[]" value="62" onclick="sum_check( this )" >
รหัส 62 ชื่อสินค้า เชนไดร้ท์ 2 กลิ่นลาเวนเดอร์ ขนาด<br>
<input type="checkbox" name="product_id[]" value="61" onclick="sum_check( this )" >
รหัส 61 ชื่อสินค้า เชนไดร้ท์ สูตรน้ำ ขนาด<br>
<input type="checkbox" name="product_id[]" value="60" onclick="sum_check( this )" >
รหัส 60 ชื่อสินค้า เชนไดร้ท์ 3 ขนาด<br>
<input type="checkbox" name="product_id[]" value="59" onclick="sum_check( this )" >
รหัส 59 ชื่อสินค้า เชนไดร้ท์ 2 ขนาด<br>
<input type="checkbox" name="product_id[]" value="29" onclick="sum_check( this )" >
รหัส 29 ชื่อสินค้า เชนไดร้ท์ เพาเดอร์ ขนาด500 g<br>
<input type="checkbox" name="product_id[]" value="28" onclick="sum_check( this )" >
รหัส 28 ชื่อสินค้า พรีแม็กซ์ อิมิฟอร์ซ 50 เอสซี ขนาด500 cc<br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
<div class="clear"></div>
<div class="paging_space">
<a class='current' >1</a> <a class='paginate' href='javascript: change_page(2)' >2</a></div>
</body>
</html>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 15:34:16 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองเช็คโค๊ดแล้ว สกดผิดครับ ตัวแปร chkbox กับ checkbox
แก็เป็นแบบข้างล่างครับ
$chk_arr=isset($_GET['chkbox'])? explode(',', $_GET['chkbox']) : array();
?>
<html>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 15:59:23 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
เอาไปใช้ ก็ ตัด , หลังสุดออก ทำไมไม่ทำเป็น ajax ดึง เอา อะ
Code (JavaScript)
function change_page( page ){ location.href="1.php?category_id=1&Page="+page+chk_text()+'<?=','.$_REQUEST['chkbox']?>'; }
function change_cate( cate_id ){ location.href='1.php?category_id='+cate_id+chk_text()+'<?=','.$_REQUEST['chkbox']?>'; }
|
ประวัติการแก้ไข 2014-10-22 16:12:15
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 16:06:07 |
By :
gaowteen |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
แก้ไขตามคุณChaidhanan ทำให้ checkbox คงที่ค่าให้แล้วค่ะ ^^ แต่รบกวนอีกนิดนะค่ะ พอคลิกเลือก checbox ที่ไม่ได้อยู่ในหน้าเดียวกัน พอกด submit จะส่งค่ามาแต่ค่าที่อยู่หน้าสุดท้ายค่ะ ไม่ส่งค่าก่อนที่เลือกเลยค่ะ แนบรูปมาให้ค่ะ ไม่รู้อธิบายถูกหรือเปล่า รบกวนหน่อยนะค่ะ ขอบคุณมากๆ ค่ะ
![error-chk error-chk](https://www.thaicreate.com/upload/stock/20141022164519.jpg?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 16:46:29 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (JavaScript)
<form action="2.php" method="post" name="compare" id="compare" onSubmit="return check()">
Please select Product.<br>
<?php
$show_num=0;
while ($r = mysql_fetch_assoc($rs)){
$chk=in_array( $r['product_id'], $chk_arr)? 'checked' : '';
if($chk>'') $show_num++;
?>
<input type="checkbox" name="product_id[]" value="<?=$r["product_id"];?>" onclick="sum_check( this )" <?=$chk?>>
รหัส <?=$r["product_id"];?> ชื่อสินค้า <?=$r["product_name"];?> ขนาด<?=$r["product_size"];?><br>
<?php
}
$ln=count($chk_arr);
for($show_num; $show_num<$ln; $show_num++){
?>
<input type="checkbox" name="product_id[]" value="<?=$chk_arr[$show_num];?>" checked style="display: none" >
<?php
}
?>
<input name="btnSubmit" type="submit" value="Submit">
</form>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 16:57:14 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ได้แล้วค่ะ ดีใจจัง งงๆ สับสน แก้มาหลายวันมากก่อนจะมาโพสที่นี่ ถ้าไม่ได้คุณ Chaidhanan ใจดีช่วยตั้งแต่ต้นจนจบ
คงไม่ได้แน่ๆ เลย ขอบคุณมากๆ นะค่ะ เวปนี้เป็นเหมือนอาจารย์จริงๆ เลยค่ะ เดี๋ยวขอลองไปเขียนเพิ่มบางส่วนก่อนนะค่ะ
ถ้าหากติดปัญหา อาจจะกลับมาขอคำแนะนำอีกนะค่ะ ขอบคุณมากค่ะ คุณ Chaidhanan @^_____^@
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-10-22 20:01:29 |
By :
angeleye |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
อันนี้เป็นหน้าโค้ด checkbox แล้วส่งค่าไปอีกหน้าค่ะ
Code (PHP)
<?
//เชื่่อมต่อฐานข้อมูล
$host="127.0.0.1"; // กำหนด host
$username1="root"; // กำหนด username
$pass_word="1234"; // กำหนด Password
$db="bus"; // กำหนดชื่อฐานข้อมูล
$Conn = mysql_connect( $host,$username1,$pass_word) or die ("ติดต่อฐานข้อมูลไม่ได้");// ติดต่อฐานข้อมูล
mysql_query("SET NAMES utf8",$Conn); // set กำหนดมาตราฐาน
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้"); // เลือกฐานข้อมูล
//--->
$route_id = $_POST['route_id'];
$company_id = $_POST['company_id'];
$route_name = $_POST['route_name'];
$company_name = $_POST['company_name'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<meta name='viewport' content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="css/jquery.mobile-1.4.2.min.css"/>
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/jquery.mobile-1.4.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" href="themes/nan.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<title>บริษัทรถโดยสาร</title>
</head>
<body>
<?
$sql = "select * from time t,route r,company c
where t.route_id=r.idroute and t.company_id=c.idcompany and idtime ='".$_GET["id"]."'";
$query = mysql_query($sql)or die (mysql_error());
$result = mysql_fetch_array($query);
?>
<div data-role="page" id="page">
<div data-role="panel" id="mypanel" data-display="overlay">
<ul data-role="listview" data-inset="false" >
<li data-role="list-divider">Menu</li>
<li data-icon="location"><a href="map_app.php">ค้นหาตำแหน่งปัจจุบัน</a></li>
<li data-icon="search"><a href="searchbus_app.php" data-transition="slide">ค้นหาสายรถโดยสาร</a></li>
<li data-icon="search"><a href="searchroute_app.php" data-transition="slide">ค้นหาจุดจอดรถ</a></li>
<li data-role="list-divider">Other</li>
<li data-icon="info"><a href="about.php" data-transition="slide">About</a></li>
<li data-icon="delete"><a href="#" data-rel="close">Close Menu</a></li>
</ul>
</div>
<div data-role="header">
<h1><img src="img/Lo.png" width="50" height="43" alt=""> Bus Korat</h1>
<a href="#mypanel" data-icon="bullets" data-iconpos="notext">menu</a> </div>
<form id = "myform1" action="compare_app.php" method="post">
<div data-role="content">
<?
$sql="select*from time t,route r,company c
where t.route_id=r.idroute and t.company_id=c.idcompany and route_id='".$_GET["idroute"]."'group by c.company_name";
$result=mysql_query($sql)or die (mysql_error());
$num_row = mysql_num_rows($result);
if ($num_row==0){
?>
<div style="text-align:center">
<h2>oops!</h2>
<p style="color:#F00">Sorry,No Data in this </p>
</div>
<?
} else{
?>
<legend>บริษัทรถโดยสาร</legend>
<?
while ($objResult = mysql_fetch_array($result))
{
?>
<fieldset data-role="controlgroup">
<input name="company_id[]" type="checkbox" id="company_id[]" value="<?=$objResult["company_id"];?>"/>
<label for="company_id">
<?=$objResult["company_name"];?>
</label>
</fieldset>
<?
}
?>
<?
}
?>
</div>
<input type="submit" name="sub" value="แสดงข้อมูล">
</form>
<div data-role="footer">
<h4> </h4>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
|
ประวัติการแก้ไข 2015-05-22 22:28:23
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-05-22 22:26:24 |
By :
nanza |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (C#)
<?php
//เชื่่อมต่อฐานข้อมูล
$host="127.0.0.1"; // กำหนด host
$username1="root"; // กำหนด username
$pass_word="1234"; // กำหนด Password
$db="bus"; // กำหนดชื่อฐานข้อมูล
$Conn = mysql_connect( $host,$username1,$pass_word) or die ("ติดต่อฐานข้อมูลไม่ได้");// ติดต่อฐานข้อมูล
mysql_query("SET NAMES utf8",$Conn); // set กำหนดมาตราฐาน
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้"); // เลือกฐานข้อมูล
//--->
$in_value = implode(',' , $_POST['company_id']);
$sql = mysql_query($qrString ="select c.company_name,t.time,r.price,c.phone from time t,route r,company c
where t.route_id=r.idroute and t.company_id=c.idcompany and company_id in ($in_value)
") or die( mysql_error() . '<br>' . $qrString );
?>
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content="width=device-width, initial-scale=1"/>
<script src="js/jquery.mobile-1.4.2.min.js"></script>
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/jquery.mobile-1.4.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" href="themes/nan.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="css/jquery.mobile-1.4.2.min.css"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<title>เปรียบเทียบ</title>
</head>
<body>
<div data-role="page" id="page">
<div data-role="header">
<h1><img src="img/Lo.png" width="50" height="43" alt=""> Bus Korat</h1>
</div>
<div data-role="content">
<p>
<?$id = $row_show['idroute']?>
<?
while( $r = mysql_fetch_assoc($sql) ){
echo "<div style='float:left; width:400px;'>";
echo "<table width='60%' border='1' cellspacing='1' cellpadding='1'>";
echo "".$r["company_name"]."<br/>";
echo nl2br("<tr><td>".$r["time"]."</td></tr><br/>");
echo "<tr><td>ราคา : ".$r["price"]." บาท</td></tr>";
echo "<tr><td>ติดต่อสอบถาม : ".$r["phone"]."</td></tr>";
echo "</table><br/>";
echo "</div>";
}
?>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div data-role="footer">
<h4></h4>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-05-22 22:27:10 |
By :
nanza |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 02
|