|
 |
|
*** ปรึกษาเรื่องนับ ครั้งของข่าว *** ผมอยากจะเพิ่มข้อมูลในครั้งที่ 2 (ฟิลด์ ชื่อ number คือครั้ง) |
|
 |
|
|
 |
 |
|
และข่าวหนึ่งข่าว จะไม่มีครั้งซ้ำกันด้วยครับ เขียนประมาณไหนครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-07-02 15:24:10 |
By :
chuensanguan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
// เพิ่มจำนวนลำดับให้ Number
// ---- By P@e. ----
include("connect.inc.php");
$sql_num = "SELECT max(number) FROM table";
$result = mysql_query($sql_num,$con) or die ("ไม่สามารถ Select Number ได้");
while($r = mysql_fetch_array($result))
{//-
if($r != 'null')
{//ถ้าข้อมูลในฟิลด์ที่ select ไม่เท่ากับค่าว่าง
$number = $r["max(number)"]+1;//ให้บวกค่าเพิ่มอีก 1
}
else { $number=1; }
}//-
?>
**** ลองรันดูครับ ผิดพลาดตรงไหนขออภัยด้วย เพราะเขียนสดๆ
|
 |
 |
 |
 |
Date :
2009-07-02 16:03:47 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ นำไปพลิกแพลงได้ดีเลยทีเดียว +ให้
|
 |
 |
 |
 |
Date :
2009-07-12 23:59:20 |
By :
chuensanguan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ 
|
 |
 |
 |
 |
Date :
2009-07-13 06:53:53 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันจะเข้า เงื่อนไข
if($r != 'null')
ได้อย่างไร
|
 |
 |
 |
 |
Date :
2009-07-13 09:07:15 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
if($r != 'null')
เงื่อนไขนี้ ถ้ามีข้อมูลแล้ว ให้เอา MAX + เพิ่ม 1
ถ้าไม่ใช้ก็ให้ = 1
|
 |
 |
 |
 |
Date :
2009-07-13 09:13:14 |
By :
taobsd |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|