Fri 22 Dec 2006 09:14:31
สวัสดีครับ
ผมขอรบกวนขอคำแนะนำในเรื่องของการนับจำนวนข้อมูลครับ คือโปรแกรมไม่นับสะสมไปเรื่อยๆ แต่ละหน้าผมมี 30 ข้อมูล โปรแกรมก็จะนับหน้าที่ 1 ข้อมูลที่1-30 พอขึ้นหน้าที่ 2 ควรที่จะนับต่อเป็น 31-60 แต่โปรแกรมกลับมาเริ่มนับใหม่เป็น 1-30 เป็นอย่างนี้ทุกๆหน้าครับ
อย่างไรช่วยแนะนำด้วยนะครับว่าต้องแก้ไขอย่างไร
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<center>
<?
$pagelen = 30 ;
$_GET["page"] = $_REQUEST['page'];
if (empty($_GET["page"] )) { $_GET["page"] =1; }
require("config.inc.php");
if(!$link)
{
print("Error");
}
else
{
mysql_select_db("fooddirectories_com_-_company", $link);
$sql="SELECT COUNT(company) AS num FROM company WHERE country like '".$country."' and ".$product."=1 order by company asc";
$res=mysql_query($sql, $link);
$row = mysql_fetch_array($res, MYSQL_ASSOC);
echo"<span class='link10'>";
echo $row["num"];
$name = "";
switch($product){
case "agri":
$name = "Agricultural Product";
break;
case"alkohol":
$name = "Alkoholic Beverages";
break;
case"nonal":
$name = "Non Alkoholic Beverages";
break;
case"bakery":
$name = "Bakery Products";
break;
case"cannedfood":
$name = "Canned Food";
break;
case"cereals":
$name = "Cereals, Grains, Flours";
break;
case"candies":
$name = "Candies, Snacks, Desserts";
break;
case"sugar":
$name = "Sugar, Honey, Sweeteners";
break;
case"coffee":
$name = "Coffee, Tea, Cacao";
break;
case"condiments":
$name = "Condiments, Spices, Herbs";
break;
case"foodin":
$name = "Food Ingredients";
break;
case"fruits":
$name = "Fruits and Vegetables";
break;
case"dressings":
$name = "Dressings and Seasonings";
break;
case"meat":
$name = "Meat, Meat Products";
break;
case"milk":
$name = "Milk, Cheese,Cream";
break;
case"oil":
$name = "Oil, Fats Products";
break;
case"organic":
$name = "Organic Products";
break;
case"pasta":
$name = "Pasta, Sauces, Soups";
break;
case"ready":
$name = "Ready and Convenience Food";
break;
case"seafood":
$name = "Seafood, Fish Products";
break;
}
echo"<span class='link20'> '".$country."' companies in ".$name." group";
echo"<br><br>";
$sql = "SELECT company, country, email1 from company WHERE country like '".$country."' and ".$product."=1 order by company asc";
$res=mysql_query($sql,$link);
$num_rows=mysql_num_rows($res);
$totalpage = ceil($num_rows / $pagelen);
$goto = ($_GET["page"] -1) * $pagelen;
$sql = "SELECT company, email1 from company WHERE country like '".$country."' and ".$product."=1 order by company asc LIMIT $goto, $pagelen";
$res = mysql_query( $sql,$link );
echo"<table border=0 cellpadding=3 cellspacing=0>";
echo"<tr>";
echo"<td width='50' bgcolor='#666666'><span class='link36'><center><b>No.</center></span></td>";
echo"<td width='250' bgcolor='#666666'><span class='link36'><center><b>Company</center></span></td>";
echo"<td width='250' bgcolor='#666666'><span class='link36'><center><b>Email</b></center></span></td></tr>";
$i=1;
while($row=mysql_fetch_array($res,MYSQL_ASSOC))
{
echo"<tr>";
echo"<td width='50'><span class='link7'>".$i."</span></td>";
$i++;
echo"<td width='250'>
<a href="javascript:;" onclick="window.open('popup_company.php?email1=".$row["email1"]."', 'pw', 'width=450,height=450,toolbars=no,status=no');">
<span class='link7'>".$row["company"]."</a></span></td>";
echo"<td width='250'><span class='link7'>".((isset($_SESSION["active"])&&$_SESSION["active"]="ok")?$row["email1"]:"Member only")."</span></td></tr>";
}
echo "</table>";
if ($_GET["page"] > 1) {
$back = $_GET["page"] - 1;
echo "<a href="".$_SERVER["PHP_SELF"]."?page=".$i."&alphabet=".$_GET["alphabet"].""><img src="main_first.gif" border="0" align="absmiddle" alt="First"></a>n";
echo "<a href="".$_SERVER["PHP_SELF"]."?page=".$i."&alphabet=".$_GET["alphabet"]."=".$back.""><img src="main_previous.gif" border="0" align="absmiddle" alt="Previous"></a>";
}
for($i=1 ; $i<=$totalpage ; $i++) {
if ($i == $_GET["page"] ) {
echo " [<b><font size =+1 color=#990000>$i</font></b>] n";
} else {
echo " <a href="".$_SERVER["PHP_SELF"]."?page=".$i."&alphabet=".$_GET["alphabet"]."">".$i."</a>";
}
}
if ($_GET["page"] < $totalpage) {
$next = $_GET["page"] +1;
echo "<a href="".$_SERVER["PHP_SELF"]."?page=".$i."&alphabet=".$_GET["alphabet"]."=".$next.""><img src="main_next.gif" border="0" align="absmiddle" alt="Next"></a>";
echo " <a href="$PHP_SELF?page=".$totalpage.""><img src="main_last.gif" border="0" align="absmiddle" alt="Last"></a> n";
}
}
?>
Fri 22 Dec 2006 14:07:22
สวัสดีและขอขอบคุณ คุณ Administrator สำหรับคำแนะนำครับ แก้ได้แล้วครับ
อนันต์

















