|
 |
|
เรื่องเกี่ยวกับการเก็บค่าตัวแปลครับไม่ทราบว่าต้องเทียบยัง |
|
 |
|
|
 |
 |
|
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>
<title> new document </title>
</head>
<body>
<a href="test.php?bt= ธีรวุฒิ แซ่ลี้">ธีรวุฒิ แซ่ลี้</a>
<br/>
<br/>
<a href="test.php?bt=ธนโรจน์ เพียวงษ์">ธนโรจน์ เพียวงษ์</a>
<br/>
<br/>
<?php
/* มันยากไป ผมทำไม่เป็น */
/*
$bt1=$_POST['bt1']; ธีรวุฒิ แซ่ลี้
$bt2=$_POST['bt2']; ธนโรจน์ เพียวงษ์
$bt3=$_POST['bt3']; วรพจน์ ลังกาวิเขต
$bt4=$_POST['bt4']; เฉลิม แก้วสา
if($bt1=="bt1")
{
$use="ธีรวุฒิ แซ่ลี้";
}
else if ($bt2=="$bt2")
{
$use="ธนโรจน์ เพียวงษ์";
}
else if ($bt3=="$bt3")
{
$use="วรพจน์ ลังกาวิเขต";
}
else if ($bt4=="$bt4")
{
$use="เฉลิม แก้วสา";
}
คำสั่ง บันทึกลง db
*/
/* ทำเป็นแต่ง่ายๆ แบบนี้ */
if($_GET['bt'] !=""){
$use = $_GET['bt'];
echo $sql="insert into tb_sigin values('','$use','$date','$in','')"; //ตรง $use อยากให้มันเก็บค่าที่ถูกต้องเมื่อทำการ เปรียบเทียบแล้วครับ
}
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-01-12 13:26:15 |
By :
peterXP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันเป็นแบบนี้ครับ ตรงหน้า from ผมใช้เป็น checkbox ในการเลือกเพื่อส่งค่า แล้วกำหนดตัวแปลเป็น bt1,bt2,bt3,bt4 แล้วสั่งให้มันส่งค่ามาหน้าที่ต้องทำการบันทึก
ตรงหน้า บันทึก ผมได้ทำการ ประกาศตัวแปลซึ่งได้แก่
$bt1=$_post['bt1'] ชื่อ a
$bt2=$_post['bt2'] ชื่อ b
$bt3=$_post['bt3'] ชื่อ c
$bt4=$_post['bt4'] ชื่อ d
แล้วผมก็จะทำการบันทึกโดยเขียนแบบนี้
$sql="insert into tb_sigin values('','$use','$date','$in','')";
$result=mysql_db_query($dbname,$sql);
ที่เนี่ย ตรงตัวแปล $use เนี่ยผมต้องเขียนเปรียบเทียบยังไงถึงจะได้ค่าที่ผมเลือกไว้ เช่นหน้า แรกผม เลือก checkbox คนที่ 4 ผมอยากจะให้มันเก็บค่าคนที่ 4 เลย โดยใช้ ตัวแปล $use เก็บต้องเขียนเปรียบเทียบยังไงอะครับ รบกวนนิสนึงครับ
|
 |
 |
 |
 |
Date :
2011-01-12 13:35:46 |
By :
chonburi f.c |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตกลง input เป็น checkbox นะ (เลือกได้หลายค่า)
ไม่้ตั้องตั้งชื่อตัวแปรเยอะแยะขนาดนั้นครับ
$bt1=$_post['bt1'] ชื่อ a
$bt2=$_post['bt2'] ชื่อ b
$bt3=$_post['bt3'] ชื่อ c
$bt4=$_post['bt4'] ชื่อ d
ก็ตั้งชื่อแบบ array
<input type="checkbox" name="del[]" value ="1"> นาย a<br>
<input type="checkbox" name="del[]" value ="2"> รายการที่ 2<br>
<input type="checkbox" name="del[]" value ="3"> รายการที่ 3<br>
foreach แล้ว insert
|
 |
 |
 |
 |
Date :
2011-01-12 13:54:25 |
By :
peterXP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เงื่อนไขแบบนี้ยังไม่เคยเขียนอะครับ แนะนำทีครับ แต่ตอนนี้ได้แล้วครับ
ใช้แบบนี้อะ
Code (PHP)
$bt=$_POST['bt'];
$bt2=$_POST['bt2'];
$bt3=$_POST['bt3'];
$bt4=$_POST['bt4'];
$date=date(" Y-m-d H:i:s ");
$datein=date(" Y-m-d H:i:s ");
if ($_POST['bt']=="wut"){
$use = "ธีรวุฒิ แซ่ลี้";
}
else if ($_POST['bt2']=="ธนโรจน์ เพียวงษ์"){
$use = $_POST['bt2'];
}
else if ($_POST['bt3']=="วรพจน์ ลังกาวิเขต"){
$use = $_POST['bt3'];
}
else if ($_POST['bt4']=="เฉลิม แก้วสา"){
$use = $_POST['bt4'];
}
$sql="insert into tb_sigin values('','$use','$date','$datein','')";
$result=mysql_db_query($dbname,$sql);
|
 |
 |
 |
 |
Date :
2011-01-12 14:06:28 |
By :
chonburi f.c |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หมายถึง 4 คนนี้เลือกคนใดคนหนึ่ง หรือครับ
|
 |
 |
 |
 |
Date :
2011-01-12 14:10:49 |
By :
ไวยวิทย์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเป็น radio แทนละ ครับ
Code (PHP)
<?php if(empty($_POST)){?>
<form id="form1" name="form1" method="post" action="">
<?php for($i=0;$i<5;$i++){ ?>
<input type="radio" name="radio" id="radio" value="คนที่<?php echo $i; ?>" />
<label for="radio">คนที่ <?php echo $i; ?></label>
<br />
<?php } ?>
<input name="" type="submit" value="Submit" />
</form>
<?php }else{ ?>
<?php echo "คนที่คุณเลือกคือ :".$_POST['radio']; ?>
<?php } ?>
เลือกคนไหน ก็ Add คนนั้นไปเลย ถ้าหากว่าสี่คนเลือกคนใดคนหนึ่ง
|
ประวัติการแก้ไข 2011-01-12 15:02:30
 |
 |
 |
 |
Date :
2011-01-12 15:01:36 |
By :
ไวยวิทย์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เลือกหมดเลยคับ ผมโลภ 555+
|
 |
 |
 |
 |
Date :
2011-01-12 18:12:46 |
By :
teez1232002 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|