|
 |
|
หนูเรียกชื่อขึ้นโชว์จากตารางหนึ่ง แล้วต้องการนำไอดีของชื่อที่โชว์ไปเก็บอีกตารางหนึ่ง ทำไงหรอค่ะ ผู้รู้ช่วยตอบทีค่ะ ขอบคุญมักๆ |
|
 |
|
|
 |
 |
|
แบบเราเขียนเรา SELECT และเทียบ id อะ
|
 |
 |
 |
 |
Date :
2010-12-23 15:55:53 |
By :
deedee2338 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$sql = "select ไอดี from ตารางที่เก็บ where columnที่เก็ชื่อ='ชื่อที่กรอก'";
$dbquery = mysql_db_query($dbname, $sql);
// หาจำนวนเรกคอร์ดข้อมูล
$num_rows = mysql_num_rows($dbquery);
if($num_rows==1){
ให้ INSERT ข้อมูล
}
|
ประวัติการแก้ไข 2010-12-23 16:01:55
 |
 |
 |
 |
Date :
2010-12-23 16:01:32 |
By :
EucifeR |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้เป็นโค้ดที่ทำอยู่ ลองดูกันหน่อยนะค่ะ หนูทำมาหลายวันแล้ว มึ้น.....มึน
<?
include("connectDB.php");
$result = mysql_query("select * from task");
// store the record of the "example" table into $row
?>
<!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>
<form action="role_task.php" method="post">
<p> </p>
<table width="200" border="1" align="center">
<tr>
<td>role name</td>
<td><label for="select"></label>
<select name="role" size="1" id="select" >
<option value="admin">admin</option>
<option value="accountant">accountant</option>
<option value="applicant">applicant</option>
<option value="manager">manager</option>
<option value="employee">employee</option>
</select></td>
</tr>
<tr>
<td>description</td>
<td><label for="textarea"></label>
<textarea name="desc" id="textarea" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td>task</td>
<td>
<?php
echo "<select =\"TaskName\" >";
echo "<option size =1>Select</option>";
if(mysql_num_rows($result))
{
while($row = mysql_fetch_assoc($result))
{
$task_id = $row[TaskName];
echo "<option >$row[TaskName]</option>";
}
}
else {
echo "<option>No Names Present</option>";
}
?>
</td>
</tr>
<td><label for="select2"></label>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<?
include("connectDB.php");
$name = $_POST['role'];
$description = $_POST['desc'];
$task = $_POST['TaskName'];
$insert = mysql_query("INSERT INTO role(RoleName,RoleDesc) VALUES ('$name','$description')");
mysql_query($insert);
$select = mysql_query("select RoleId from role where RoleName = '$name'");
while($row2 = mysql_fetch_array($select))
{
echo $row2['RoleId'];
}
$select2 = mysql_query("select TaskId from task where TaskName = '$task'");
if(mysql_num_rows($select2))
{
while($row = mysql_fetch_array($select2))
{
echo $row['TaskId'];
}
}
$insert1 = mysql_query("INSERT INTO role_task(RoleId,TaskId) VALUES ('$row2','$row')");
mysql_query($insert1);
?>
<!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>
</body>
</html>
จะต้องแก้ไขตรงไหนอ่ะค่ะ 
|
 |
 |
 |
 |
Date :
2010-12-23 16:01:49 |
By :
หนูนา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูแล้วค่ะ แต่ใช้ไม่ได้อ่ะ
|
 |
 |
 |
 |
Date :
2010-12-23 17:01:39 |
By :
หนูนา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณนะคะ
|
 |
 |
 |
 |
Date :
2010-12-23 19:29:39 |
By :
หนูนา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|