|
 |
|
รบกวนช่วยดูโค้ดให้หน่อยครับ คือว่าเป็นโค้ดเกี่ยวกับ เปลี่ยนหน้า 1 2 นะครับพอ เปลี่ยนแล้วมันไม่ส่งไปค่าไปตรงกับที่จะแสดงกลับอีกฐานข้อมูลนึ่งนะครับ |
|
 |
|
|
 |
 |
|
นึกไม่ออกนะครับ ว่าจะส่งยังไงนะครับให้ตรง ให้ฐานข้อมูล รบกวนช่วยนะครับ
ไม่ทราบจริงว่าจะส่ง 2 ตัวแปรยังไงงครับ ทั้งฐานข้อมูล รูป และก็ฐานข้อมูล โพส
ฐานข้อมูลรูป
$sql = "SELECT * FROM product_moter WHERE ProductM_ID = $ProductM_ID;";
ฐานข้อมูลโพส
$sql = "SELECT * FROM comments_m WHERE ID_ProduetM = $ProductM_ID;";
|
ประวัติการแก้ไข 2012-12-12 00:30:21
 |
 |
 |
 |
Date :
2012-12-12 00:27:52 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองไปดูนี่ครับ
Code (PHP)
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
PHP MySQL Search Record Paging/Pagination
|
 |
 |
 |
 |
Date :
2012-12-12 05:48:17 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับพี่เดียวยังไงขอลองเอาไปศึกษาดูก่อนได้ไม่ได้ยังไงต้องขอรบกวนอีกทีนะครับ
|
 |
 |
 |
 |
Date :
2012-12-13 01:11:16 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่งค่าไปได้แล้วครับ แล้วเชื่อมต่อกับฐานข้อมูล แรก ได้แล้ว
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&ProductM_ID=$ProductM_ID'><< Back</a> ";
แต่มันติด อยู่ตรงโค้ดข้างล่างนี้นะครับ ที่ทำให้ ไม่ขึ้น ฐานข้อมุลอีกอัน
Code (PHP)
$strSQL .=" order by ID_CM DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="400" border="0" align="center">
<?
while($result = mysql_fetch_array($objQuery))
และขึ้น ว่า
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
รบกวนหน่อยนะครับ
|
ประวัติการแก้ไข 2012-12-13 03:56:58 2012-12-13 04:01:10 2012-12-13 04:01:34
 |
 |
 |
 |
Date :
2012-12-13 03:53:02 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
echo $strSQL;
เอา SQL ออกมาดูครับ
|
 |
 |
 |
 |
Date :
2012-12-13 08:25:09 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ออกมาตามนี้นะครับ
SELECT * FROM comments_m WHERE ID_ProduetM = 00001; order by ID_CM DESC LIMIT 0 , 4
ลองเอาไปรันเดี่ยวๆ ก็ใช่ได้ปกติ
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include("connect.php");
$strSQL = "SELECT * FROM comments_m";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 4; // 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;
}
$strSQL .=" order by ID_CM DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
echo $strSQL;
?>
<table width="400" border="0" align="center">
<?
while($result = mysql_fetch_array($objQuery))
{
?>
<!--view comments -->
<table width="400" border="0" align="center">
<tr >
<td>ชื่อผู้โพส <B><?=$result["Username_CM"];?></B></td>
<td> </td>
</tr>
<tr>
<td><a href="cm_moterselect.php?id_cm=<?=$result["ID_CM"];?>">- <?=$result["Text_CM"];?></a> [<?=$result["count"]; ?>]</td>
<td> </td>
</tr>
<tr>
<td><?=$result["Day_CM"]; ?></td>
<td> </td>
</tr>
</tr>
<tr>
<td> </td>
<td align="right">
<?php
if ($_SESSION["Status"] =="ADMIN") { ?>
<a href="cm_moteredit.php?id_cm=<?=$result["ID_CM"];?>">แก้ไข</a> <a href="cm_moterdelete.php?id_cm=<?=$result["ID_CM"];?>" onClick='return Conf(this)'>ลบ</a>
<?
}
else if($result["Username_CM"] == $_SESSION["Name"]) {
?>
<a href="cm_moteredit.php?id_cm=<?=$result["ID_CM"];?>">แก้ไข</a> <a href="cm_moterdelete.php?id_cm=<?=$result["ID_CM"];?>" onClick='return Conf(this)'>ลบ</a>
<?
}
?>
</td>
</tr>
<!--viw answer comments-->
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&ProductM_ID=$ProductM_ID'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&ProductM_ID=$ProductM_ID'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&ProductM_ID=$ProductM_ID'>Next>></a> ";
}
mysql_close();
?>
</body>
</html>
|
ประวัติการแก้ไข 2012-12-13 10:14:28 2012-12-13 10:18:19 2012-12-13 15:40:03
 |
 |
 |
 |
Date :
2012-12-13 10:03:36 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนช่วยดูให้หน่อยนะครับ ว่าต้องทำยังไง แก้ไม่ได้จริงๆครับ
|
 |
 |
 |
 |
Date :
2012-12-14 01:07:09 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ใช่ไมครับที่มันเกินมา
order by ID_CM DESC LIMIT 0 , 4
คือตรงส่วนนี้นะครับ
Code (PHP)
$strSQL .=" order by ID_CM DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="400" border="0" align="center">
<?
while($result = mysql_fetch_array($objQuery))
แต่พอผมเอาไปรันที่ไม่ต้อง เชื่อมต่อ 2 ฐานข้อมูลก็ใช่งานได้ปกตินะครับ แต่ถ้าไม่เอา
$strSQL .=" order by ID_CM DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
เข้าไปในตัวแปร $result พอกดไปหน้าต่อ มันไม่ทำงานนะครับ
|
 |
 |
 |
 |
Date :
2012-12-14 21:29:23 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนช่วยดูให้หน่อยนะครับ ไม่ได้จริงๆลองมาหลายหนแล้ว พอกดหน้า ทัดถัดไป แล้วส่งค่าไปด้วยด้วย ก็เชื่อมต่อฐานข้อมูลแรกอยู่ แต่ฐานข้อมูลที่สอง ไม่แสดง ถ้าเก็บค่า
$strSQL .=" order by ID_CM DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
มาใส่ในตัวแปร while($result = mysql_fetch_array($objQuery))
แต่ถ้า ไม่เอา order by ID_CM DESC LIMIT $Page_Start , $Per_Page";
พอกดหน้าทัดไป ก็ไม่แสดง ค่าที่เหลือที่อยู่อีกหน้าหนึ่ง
|
 |
 |
 |
 |
Date :
2012-12-16 04:35:34 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรง
Code (PHP)
while($result = mysql_fetch_array($objQuery))
ค่า $result มันซ้ำกับค่า $result ในบรรทัดที่ 6 ลองเปลี่ยนเป็น
Code (PHP)
while($result1 = mysql_fetch_array($objQuery))
แทนดูครับ น่าจะได้นะผมว่า 
|
 |
 |
 |
 |
Date :
2012-12-17 17:28:01 |
By :
theyounggun |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ออ ได้แล้วครับ มันผิดนิดหน่อยตรงเกินมา ; ที่พี่ mr.win บอกมานะครับ ลองแก้
$strSQL = "SELECT * FROM comments_m WHERE ID_ProduetM = $ProductM_ID order by ID_CM ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
ก็ได้แล้วครับ ขอบคุณมากครับที่ช่วยเหลือ
|
 |
 |
 |
 |
Date :
2012-12-17 19:36:55 |
By :
เกียรติศักดิ์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|