Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สังสัยมากเลยครับว่าทำไมใช่โค้ดแบ่งหน้า ที่ใช่กับอันหนึ่งได้แล้วพอมาแก้กลับใช่อีกอันไม่ได้ครับช่วยทีคัรบ



 

สังสัยมากเลยครับว่าทำไมใช่โค้ดแบ่งหน้า ที่ใช่กับอันหนึ่งได้แล้วพอมาแก้กลับใช่อีกอันไม่ได้ครับช่วยทีคัรบ

 



Topic : 082450



โพสกระทู้ ( 79 )
บทความ ( 0 )



สถานะออฟไลน์




นี้คือภาพที่ค้นหาตอนแรกนะครับ เพจ1

1

นี้คือเมื่อกดเพจ 2 และต่อไปเรื่อยก็เป็นเหมือนกัน

/

Code (PHP)
            <td height="302" nowrap="nowrap"><form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get" name="frmSearch" id="frmSearch">

              <!-- สร้างตัวแปร เพื่อกำหนด ตัวควบคุม รอบของโปรแกรม ชื่อ command -->

              <input type="hidden" name="command" value="" />

              <table width="60%"align="center" >

                <tr>

                  <td height="69"><div align="center"><strong>ระบบสารสนเทศโครงการศึกษาเฉพาะเรื่องจัดทำเพื่อใช้สืบค้นระบบฐานข้อมูล</strong></div>

                    <hr />

                    <div>

                      <blockquote>

                        <p>ระบบสืบค้นฐานข้อมูลโครงการศึกษาเฉพาะเรื่อง โดยสืบค้นจาก ; ชื่อเรื่อง, อาจารย์ที่ปรึกษา, ระดับคุณภาพ (ดีเยี่ยม, ดี, ผ่าน, ควรปรับปรุง), ปีการศึกษา (2553, 2554, 2555, .........) </p>

                      </blockquote>

                    </div></td>

                </tr>

              </table>

              <table width="598" align="center">

                <tr>

                  <th width="590"><p>คำค้น

                   <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>" size="50" />
       			<br />
                
                <label><input type="checkbox" name="grade[]" value="1" id="grade_1" />
                ดีเยี่ยม</label>
               
                <label><input type="checkbox" name="grade[]" value="2" id="grade_2" />ดี</label>
                
                <label><input type="checkbox" name="grade[]" value="3" id="grade_3" />ผ่าน</label>
                  
                <label><input type="checkbox" name="grade[]" value="4" id="grade_4" />ควรปรับปรุง</label>
                  
                <label><input type="checkbox" name="grade[]" value="5" id="grade_5" />รอการสอบ</label> 
                
                <input type="submit" value="Search" onclick="frmSearch.command.value='SEARCH';"/>

                  </p></th>

                </tr>

                <tr>

                  <td><?

		

$command = $_GET["command"];

		

{

include("connect.php"); // include connect

$grade = $_GET["grade"]; // นำ grade มาใส่ตัวแปร
$txtKeyword = $_GET["txtKeyword"] ; //ใส่ตัวแปร txtKeyword
$url = '&txtKeyword='. $_GET["txtKeyword"] ; //สร้าง url สำหรับ paginate 
//; //แสดงข้อความออกมา จำนวนgrade

for($i=0;$i<count($_GET["grade"]);$i++) // วนลูป
{
//if(trim($_GET["grade"][$i]) != ""); // แสดงค่า grade
$url .= '&grade[]='. $_GET['grade']; //สร้าง url สำหรับ paginate
}

 // แสดงข้อความ



//$arr_search_condition = (array) null;



//if($grade==1 or $grade==2 or $grade==3 or $grade==4 or $grade==5)

//$arr_sub_condition[] = "p_gra=".$_GET["grade"][$i];



//if(count($arr_sub_condition)) $sub_condition = " where ".implode(" or ", $arr_sub_condition);

//$arr_search_condition[] = $sub_condition ;



$search_condition = "where "; //start condition



if(trim($txtKeyword)) { //ตัดช่องว่างหน้าหลังของ keyword ระวัง หากไม่มีค่า get มาจาก url จะ error

  $search_condition .= "( a.p_id LIKE '%$txtKeyword%'or a.p_stu_fname LIKE '%$txtKeyword%' or a.p_stu_sname LIKE '%$txtKeyword%' or c.p_adv_fname LIKE '%$txtKeyword%' or c.p_adv_sname LIKE '%$txtKeyword%' or a.p_name LIKE '%$txtKeyword%' or e.p_aca_w LIKE '%$txtKeyword%' )" ;

  /* เขียน sql ในการ join หลายตาราง ให้ระบุ table ด้วยนะครับ p_id LIKE xxx ไม่ควรเขียน ควรเขียน a.p_id ไปเลย เผื่อชื่อ column ซ้ำกัน จะได้ไม่มีปัญหาภายหลัง */

}



if (!empty($txtKeyword) && count($grade)!=0) { // ตรวจสอบว่า $textKeyword และ $grade มีค่า ให้ใส่ and คั่นประโยคด้วย

  $search_condition .= " and ";

}



if (count($grade)!=0) { // ถ้า ค่า array grade ไม่เท่ากับ 0 ให้ค้นหา p_gra ด้วย 

  $search_condition .=  "a.p_gra IN ('". implode("','", $grade) . "')"; // ค้นหา a.p_gra IN (value1,value2) 

}











$sql = " select	a.* ,b.p_num,c.p_adv_num , c.p_adv_fname , c.p_adv_sname , d.p_gra_w , e.p_aca_w
from senior_n a left join senior_num b on (a.p_numkey = b.p_numkey)
left join senior_adv c on (a.p_adv = c.p_adv)
left join senior_gra d on (a.p_gra = d.p_gra)
left join senior_aca e on (a.p_aca = e.p_aca)
$search_condition  ";









$objQuery = mysql_query($sql) or die ("Error Query [".$sql."]");

$Num_Rows = mysql_num_rows($objQuery);





	$Per_Page = 30;   // 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 p_id ASC LIMIT $Page_Start , $Per_Page";

	$objQuery  = mysql_query($sql);



?>

                    <table width="993" border="1" align="center" class="square">
            <tr bgcolor="#551B6D"  style="color:#FFF;">
              <td width="50" height="68" align="center"><strong>รหัส</strong></td>
              <td width="292" align="center"><strong>ชื่อ Senior Project</strong></td>
              <td width="180" align="center"><strong>ชื่อนักเรียน</strong></td>
              <td width="170" align="center"><strong>ชื่ออาจารย์ที่ปรึกษา</strong></td>
              <td width="93" align="center"><strong>ระดับคะแนน</strong></td>
              <td width="83" align="center"><strong>ปีการศึกษา</strong></td>
              <td width="79" align="center"><strong>บทคัดย่อ</strong></td>
            </tr>
            <?

$Num_Rows = 0;
while($objResult = mysql_fetch_array($objQuery)) {
$Num_Rows++;
if ($Num_Rows % 2 == 0){
?>
<tr bgcolor="#E9C8FB"   >
<? 
} else {
?>
<tr bgcolor="#FFFFFF">
<?
}
?>
<td><div align="center"><?=$objResult["p_id"]?> </div></td>
<td><div align="left"><?=$objResult["p_name"];?></div></td>
<td><div align="left">
                  <?=$objResult["p_num"];?>
                <?=$objResult["p_stu_fname"];?>
                <?=$objResult["p_stu_sname"];?>
                </div></td>
<td><div align="left">
                <?=$objResult["p_adv_num"];?>
                <?=$objResult["p_adv_fname"];?>
                <?=$objResult["p_adv_sname"];?>
              </div></td>
              <td><div align="center">
                <?=$objResult["p_gra_w"]; ?>
              </div></td>
              
              <td><div align="center">
                <?=$objResult["p_aca_w"]; ?>
              </div></td>
              <td><div align="center"><a href="abs/<?=$objResult["p_abs_name"];?>"  target='_blank'>
        บทคัดย่อ
      </a></div></td>
</tr>
<?
}
?>
          </table>

                    <br />

                    ผลการค้นหาทั้งหมด

                    <?= $Num_Rows;?>

                    มีหน้าทั้งหมด :

                    <?=$Num_Pages;?>

                    หน้า :

                    <?

	if($Prev_Page)

	{

		echo ' <a href="' . $_SERVER[SCRIPT_NAME] . '?Page=' . $Prev_Page . $url. '"><<หน้าก่อนหน้า</a>';

	}



	for($i=1; $i<=$Num_Pages; $i++){

		if($i != $Page)

		{

			echo '[ <a href="'.$_SERVER[SCRIPT_NAME].'?Page='.$i . $url .'">'.$i.'</a> ]';

		}

		else

		{

			echo "<b> $i </b>";

		}

	}

	if($Page!=$Num_Pages)

	{

		echo '<a href ="'. $_SERVER[SCRIPT_NAME].'?Page='. $Next_Page . $url .'">หน้าถัดไป>></a>';

	}

	

	mysql_close();



	}	

	?></td>

                </tr>

              </table>

            </form>




คือผมทำอันหนึ่งได้แล้วในลักษณะเดียวกันเลยครับ แต่พอมาแก้เป็นอันนี้แล้วใช่ไม่ได้



Tag : PHP, MySQL, HTML/CSS, Action Script







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-08-17 00:53:19 By : crazydrogon View : 1040 Reply : 7
 

 

No. 1



โพสกระทู้ ( 105 )
บทความ ( 0 )



สถานะออฟไลน์


คาดว่าค่า grade ของอันที่ 2 มันเป็น array เลยคิวรี่ไม่ได้ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-17 02:12:56 By : Pine
 


 

No. 2



โพสกระทู้ ( 79 )
บทความ ( 0 )



สถานะออฟไลน์


ไม่นะครับ ผมใช่รูปแบบนี้กับเพจหนึ่งก็ไม่มีปัญหานะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-17 10:49:12 By : crazydrogon
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ลอง echo เอาค่า SQL ไปรันดูใน phpMyAdmin ครับ ว่ามัน Query ออกหรือไม่
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-17 14:02:51 By : mr.win
 


 

No. 4



โพสกระทู้ ( 79 )
บทความ ( 0 )



สถานะออฟไลน์


พี่วินครับ เรียกข้อมูลได้ครับแต่แบ่งหน้าแล้วเปิดหน้า ต่อไปไม่ได้อะครับ


นี้คือต้นแบบที่ผมนำมาใช่อะครับ Code (PHP)
<?

		

$command = $_GET["command"];

		

{

include("connect.php"); // include connect

$status = $_GET["status"]; // นำ status มาใส่ตัวแปร
$txtKeyword = $_GET["txtKeyword"] ; //ใส่ตัวแปร txtKeyword
$url = '&txtKeyword='. $_GET["txtKeyword"] ; //สร้าง url สำหรับ paginate 
//; //แสดงข้อความออกมา จำนวนstatus

for($i=0;$i<count($_GET["status"]);$i++) // วนลูป
{
//if(trim($_GET["status"][$i]) != ""); // แสดงค่า status
$url .= '&status[]='. $_GET['status']; //สร้าง url สำหรับ paginate
}

 // แสดงข้อความ



//$arr_search_condition = (array) null;



//if($status==0 or $status==1 or $status==2 or $status==3 or $status==4)

//$arr_sub_condition[] = "p_sta_key=".$_GET["status"][$i];



//if(count($arr_sub_condition)) $sub_condition = " where ".implode(" or ", $arr_sub_condition);

//$arr_search_condition[] = $sub_condition ;



$search_condition = "where "; //start condition



if(trim($txtKeyword)) { //ตัดช่องว่างหน้าหลังของ keyword ระวัง หากไม่มีค่า get มาจาก url จะ error

  $search_condition .= "( a.p_id LIKE '%$txtKeyword%'or a.p_stu_fname LIKE '%$txtKeyword%' or a.p_stu_sname LIKE '%$txtKeyword%' or c.p_adv_fname LIKE '%$txtKeyword%' or c.p_adv_sname LIKE '%$txtKeyword%' or a.p_name LIKE '%$txtKeyword%' )" ;

  /* เขียน sql ในการ join หลายตาราง ให้ระบุ table ด้วยนะครับ p_id LIKE xxx ไม่ควรเขียน ควรเขียน a.p_id ไปเลย เผื่อชื่อ column ซ้ำกัน จะได้ไม่มีปัญหาภายหลัง */

}



if (!empty($txtKeyword) && count($status)!=0) { // ตรวจสอบว่า $textKeyword และ $status มีค่า ให้ใส่ and คั่นประโยคด้วย

  $search_condition .= " and ";

}



if (count($status)!=0) { // ถ้า ค่า array status ไม่เท่ากับ 0 ให้ค้นหา p_sta_key ด้วย 

  $search_condition .=  "a.p_sta_key IN ('". implode("','", $status) . "')"; // ค้นหา a.p_sta_key IN (value1,value2) 

}











$sql = " select	a.* ,b.p_num,c.p_adv_num , c.p_adv_fname , c.p_adv_sname, d.p_sta

from senior_n a left join senior_num b on (a.p_numkey = b.p_numkey)

left join senior_adv c on (a.p_adv = c.p_adv)

left join senior_sta d on (a.p_sta_key = d.p_sta_key)

$search_condition ";









$objQuery = mysql_query($sql) ;

$Num_Rows = mysql_num_rows($objQuery);





	$Per_Page = 30;   // 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 p_id ASC LIMIT $Page_Start , $Per_Page";

	$objQuery  = mysql_query($sql);



?>

                    <table width="819" border="1" align="center" class="square">

                      <tr bgcolor="#551B6D"  style="color:#FFF;">

                        <td width="50" height="68" align="center"><strong>รหัส</strong></td>

                        <td width="292" align="center"><strong>ชื่อ Senior Project</strong></td>

                        <td width="180" align="center"><strong>ชื่อนักเรียน</strong></td>

                        <td width="170" align="center"><strong>ชื่ออาจารย์ที่ปรึกษา</strong></td>

                        <td width="93" align="center"><strong>ผลการอนุมัติ</strong></td>

                      </tr>

                      <?



$Num_Rows = 0;

while($objResult = mysql_fetch_array($objQuery)) {

$Num_Rows++;



if ($Num_Rows % 2 == 0){

?>

                      <tr bgcolor="#E9C8FB"   >

                        <? 

} else {

?>

                      </tr>

                      <tr bgcolor="#FFFFFF">

                        <?

}

?>

                        <td><div align="center">

                          <?=$objResult["p_id"]?>

                        </div></td>

                        <td><div align="left">

                          <?=$objResult["p_name"];?>

                        </div></td>

                        <td><div align="left">

                          <?=$objResult["p_num"];?>

                          <?=$objResult["p_stu_fname"];?>

                          <?=$objResult["p_stu_sname"];?>

                        </div></td>

                        <td><div align="left">

                          <?=$objResult["p_adv_num"];?>

                          <?=$objResult["p_adv_fname"];?>

                          <?=$objResult["p_adv_sname"];?>

                        </div></td>

                        <td><div align="center">

                          <?=$objResult["p_sta"]; ?>

                        </div></td>

                      </tr>

                      <?

}

?>

                    </table>

                    <br />

                    ผลการค้นหาทั้งหมด

                    <?= $Num_Rows;?>

                    มีหน้าทั้งหมด :

                    <?=$Num_Pages;?>

                    หน้า :

                    <?

	if($Prev_Page)

	{

		echo ' <a href="' . $_SERVER[SCRIPT_NAME] . '?Page=' . $Prev_Page . $url. '"><<หน้าก่อนหน้า</a>';

	}



	for($i=1; $i<=$Num_Pages; $i++){

		if($i != $Page)

		{

			echo '[ <a href="'.$_SERVER[SCRIPT_NAME].'?Page='.$i . $url .'">'.$i.'</a> ]';

		}

		else

		{

			echo "<b> $i </b>";

		}

	}

	if($Page!=$Num_Pages)

	{

		echo '<a href ="'. $_SERVER[SCRIPT_NAME].'?Page='. $Next_Page . $url .'">หน้าถัดไป>></a>';

	}

	

	mysql_close();



	}	

	?></td>

                </tr>

              </table>

            </form></td>

          </tr>

        </table>



ประวัติการแก้ไข
2012-08-17 20:32:50
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-17 19:54:58 By : crazydrogon
 


 

No. 5



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

รันบน server เดียวกันหรือป่าวครับ ถ้าคนละตัวกัน อาจจะเป็นปัญหาเกี่ยวกับ PHP ครับ ต้องดูในส่วนของ phpinfo ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-19 17:31:59 By : teeza2499
 


 

No. 6



โพสกระทู้ ( 41 )
บทความ ( 0 )



สถานะออฟไลน์


ตรวจสอบค่า limit ดูครับ

หรือไม่ก็ echo ค่า sql command
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-19 18:03:49 By : nontadech
 


 

No. 7



โพสกระทู้ ( 79 )
บทความ ( 0 )



สถานะออฟไลน์


เชิพเวอร์ตัวเดียวกันครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-19 19:15:43 By : crazydrogon
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สังสัยมากเลยครับว่าทำไมใช่โค้ดแบ่งหน้า ที่ใช่กับอันหนึ่งได้แล้วพอมาแก้กลับใช่อีกอันไม่ได้ครับช่วยทีคัรบ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่