|
 |
|
ผมงงครับ ช่วยหน่อยครับ .. นี่เป็น code ที่จะบันทึกข้อมูลลง databaseแต่ว่า ต้องให้มัน เช็คก่อนว่า มีค่ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
$d27 = isset($_GET['d27']) ? 1 : 0;
$d28= isset($_GET['d28']) ? 1 : 0;
$d29 = isset($_GET['d29']) ? 1 : 0;
$d30 = isset($_GET['d30']) ? 1 : 0;
$d31 = isset($_GET['d31']) ? 1 : 0;
$d01 = isset($_GET['d01']) ? 1 : 0;
$d02= isset($_GET['d02']) ? 1 : 0;
$d03 = isset($_GET['d03']) ? 1 : 0;
$d04 = isset($_GET['d04']) ? 1 : 0;
$d05 = isset($_GET['d05']) ? 1 : 0;
$d06 = isset($_GET['d06']) ? 1 : 0;
$d07= isset($_GET['d07']) ? 1 : 0;
$d08 = isset($_GET['d08']) ? 1 : 0;
$d09 = isset($_GET['d09']) ? 1 : 0;
$d10 = isset($_GET['d10']) ? 1 : 0;
$d11 = isset($_GET['d11']) ? 1 : 0;
$d12= isset($_GET['d12']) ? 1 : 0;
$d13 = isset($_GET['d13']) ? 1 : 0;
$d14 = isset($_GET['d14']) ? 1 : 0;
$d15 = isset($_GET['d15']) ? 1 : 0;
$d16 = isset($_GET['d16']) ? 1 : 0;
$d17= isset($_GET['d17']) ? 1 : 0;
$d18 = isset($_GET['d18']) ? 1 : 0;
$d19 = isset($_GET['d19']) ? 1 : 0;
$d20 = isset($_GET['d20']) ? 1 : 0;
$d21 = isset($_GET['d21']) ? 1 : 0;
$d22= isset($_GET['d22']) ? 1 : 0;
$d23 = isset($_GET['d23']) ? 1 : 0;
$d24 = isset($_GET['d24']) ? 1 : 0;
$d25 = isset($_GET['d25']) ? 1 : 0;
$d26=isset($_GET['d26']) ? 1 :0;
$Name=$_GET['Name'];
$Date=$_GET['Date'];
echo"$Date";
?>
<?
require"config/config_month_update.php";
$sql="SELECT * FROM $tb Where Name='$Name'" ;
$objQuery = mysql_query($sql);
$objResult = mysql_num_rows($objQuery);
if($objResult > 0 )
{
mysql_query("UPDATE $tb SET Name='$Name', d27='$d27',d28='$d28',d29='$d29',d30='$d30',d31='$d31',d01='$d01',d02='$d02',d03='$d03',d04='$d04',d05='$d05',d06='$d06',d07='$d07',d08='$d08',d09='$d09',d10='$d10',d10='$d10',d11='$d11',d12='$d12',d13='$d13',d14='$d14',d15='$d15',d16='$d16',d17='$d17',d18='$d18',d19='$d19',d20='$d20',d21='$d22',d23='$d23',d24='$d24',d25='$d25',d26='$d26'
WHERE Name='$Name' ");
}
else
{
mysql_query("INSERT INTO $tb (Name,d27,d28,d29,d30,d31,d01,d02,d03,d04,d05,d06,d07,d08,d09,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,Date)values('$Name','$d27','$d28','$d29','$d30','$d31','$d01','$d02','$d03','$d04','$d05','$d06','$d07','$d08','$d09','$d10','$d11','$d12','$d13','$d14','$d15','$d16','$d17','$d18','$d19','$d20','$d21','$d22','$d23','$d24','$d25','$d26','$Date')") or die ("เพิ่มข้อมูลไม่สำเร็จ <a href='test.php'><font color='#0000FF' size='2'><u>[ย้อนกลับไปเพิ่มข้อมูลเพิ่ม]</u></a>");
echo "<br><br><br><center><font color='blue' size='2'>เพิ่มข้อมูลสำเร็จ</font><center></center>";
}
mysql_close($connect);
?>
นี่เป็น code ที่จะบันทึกข้อมูลลง databaseแต่ว่า ต้องให้มัน เช็คก่อนว่า มีค่า ชื่อไรพวกนี้อยู่ป่าวพอเวลาเช็คแล้ว ถ้าไม่มีมันก็สามารถ Insert ได้ แต่ถ้ามันมีชื่อเดียวกันอยู่ใน Database ให้มัน update แต่พอมัน Update แล้วค่าที่มันมี อยู่เดิม เป็น 0 หมดเลยเลยงงครับ ช่วยหน่อยครับ
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-01-20 15:45:20 |
By :
ryuk |
View :
961 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง echo sql ออกมาดูค่ะ เช็ค field type ด้วย
สงสัยว่าทำไมต้องใช้ $d27 = isset($_GET['d27']) ? 1 : 0; คะแบบนี้มันก็จะได้แค่ 1 กับ 0 เท่านั้น แสดงว่าใช้แค่ 1 กับ 0งั้นหรอคะ
|
 |
 |
 |
 |
Date :
2010-01-20 16:20:34 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่แล้วครับ
ผมใช้แค่ 1 กับ 0 เท่านั้นครับ ตอนนี้ได้แล้วครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2010-01-20 16:51:28 |
By :
ryuk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|