|
|
|
สอบถามปัญหาครับ คือผมจะทำweb สำหรับไว้เก็บผลทดสอบ |
|
|
|
|
|
|
|
คือผมจะทำหน้าเว็บเพจไว้สำหรับเก็บผลเทสทดสอบ โดยมี selectbox 4 อัน มีความสัมพันธ์กัน ได้ตามด้านล่าง
**** ปัญหา คือ หลังจากเราเลือกข้อมูลจาก listbox แล้ว ต้องการให้ textbox แสดงชื่อเทสเคสที่เราต้องการจะเทสขึ้นมา ไม่รู้จะต้องทำยังงัย
file jsonAction.php
Code (PHP)
<?php
// Set delay 1 second.
sleep(1);
// Create connection connect to mysql database
$dbCon = mysql_connect('localhost', 'root', 'root') or die (mysql_error());
// Select database.
mysql_select_db('rtbsv81', $dbCon) or die (mysql_error());
// Set encoding.
mysql_query('SET NAMES UTF8');
// Next dropdown list.
$nextList = isset($_GET['nextList']) ? $_GET['nextList'] : '';
switch($nextList) {
case 'Case':
$topics_ID = isset($_GET['topics_ID']) ? $_GET['topics_ID'] : '';
$result = mysql_query("
SELECT DISTINCT
case_ID,
case_Name
FROM
service01
WHERE topics_ID = '{$topics_ID}'
ORDER BY case_ID ASC;
");
break;
case 'Subcase':
$case_ID = isset($_GET['case_ID']) ? $_GET['case_ID'] : '';
$result = mysql_query("
SELECT DISTINCT
subcase_ID,
subcase_Name
FROM
service01
WHERE case_ID = '{$case_ID}'
ORDER BY subcase_ID ASC;
");
break;
}
$data = array();
while($row = mysql_fetch_assoc($result)) {
$data[] = $row;
}
// Print the JSON representation of a value
echo json_encode($data);
?>
file update.php
Code (PHP)
<?php
// Load jQuery library from google.
$jqLib = 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js';
// Create connection connect to mysql database
$dbCon = mysql_connect('localhost', 'root', 'root') or die (mysql_error());
// Select database.
mysql_select_db('rtbsv81', $dbCon) or die (mysql_error());
// Set encoding.
mysql_query('SET NAMES UTF8');
?>
<!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>Update Test Results</title>
<script type="text/javascript" src="<?php echo $jqLib; ?>"></script>
<script type="text/javascript">
// Specify a function to execute when the DOM is fully loaded.
$(function(){
var defaultOption = '<option value=""> ------- select ------ </option>';
var loadingImage = '<img src="images/loading4.gif" alt="loading" />';
// Bind an event handler to the "change" JavaScript event, or trigger that event on an element.
$('#selTopic').change(function() {
$("#selCase").html(defaultOption);
$("#selSubcase").html(defaultOption);
// Perform an asynchronous HTTP (Ajax) request.
$.ajax({
// A string containing the URL to which the request is sent.
url: "jsonAction.php",
// Data to be sent to the server.
data: ({ nextList : 'Case', topics_ID: $('#selTopic').val() }),
// The type of data that you're expecting back from the server.
dataType: "json",
// beforeSend is called before the request is sent
beforeSend: function() {
$("#waitCase").html(loadingImage);
},
// success is called if the request succeeds.
success: function(json){
$("#waitCase").html("");
// Iterate over a jQuery object, executing a function for each matched element.
$.each(json, function(index, value) {
// Insert content, specified by the parameter, to the end of each element
// in the set of matched elements.
$("#selCase").append('<option value="' + value.case_ID +
'">' + value.case_ID + '</option>');
});
}
});
});
$('#selCase').change(function() {
$("#selSubcase").html(defaultOption);
$.ajax({
url: "jsonAction.php",
data: ({ nextList : 'Subcase', case_ID: $('#selCase').val() }),
dataType: "json",
beforeSend: function() {
$("#waitSubcase").html(loadingImage);
},
success: function(json){
$("#waitSubcase").html("");
$.each(json, function(index, value) {
$("#selSubcase").append('<option value="' + value.subcase_ID +
'">' + value.subcase_ID + '</option>');
});
}
});
});
});
</script>
<style type="text/css">
body {
font-family: Verdana, Geneva, sans-serif;
font-size: 13px;
}
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="1081" border="0" cellspacing="1" cellpadding="1">
<tr>
<th width="300" align="left" valign="top" scope="col"> </th>
<th width="200" align="left" valign="top" scope="col"> </th>
<th width="150" scope="col"> </th>
<th width="166" align="left" valign="top" scope="col"> </th>
<th width="149" align="left" valign="top" scope="col"> </th>
<th width="178" align="left" valign="top" scope="col"> </th>
</tr>
<!-- ######################## Priority #################################### -->
<tr>
<td width="300"><strong>Priority</strong></td>
<td align="left" valign="top">
<select name="priority" size="1" id="priority">
<option> --- Priority ---</option>
</select></td>
<td> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<!-- ######################## Topic ID #################################### -->
<tr>
<td> </td>
<td align="left" valign="top"> </td>
<td> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td><strong>Topic ID :</strong></td>
<td align="left" valign="top">
<select name="selTopic" id="selTopic" size="1">
<option value=""> ------- select ------ </option>
<?php
$result = mysql_query("SELECT DISTINCT topics_ID,topics_Name FROM service01 ORDER BY topics_ID ASC;");
while($row = mysql_fetch_assoc($result))
{
echo '<option value="', $row['topics_ID'], '">', $row['topics_ID'],'</option>';
}
?>
</select></td>
<td><strong>Topics name</strong></td>
<td align="left" valign="top">
<?php
echo '<input values="', $result['topics_Name'], $row['topics_Name'],'"/>';
?>
</td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td> </td>
<td align="left" valign="top"> </td>
<td> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td width="300"><strong>Test case ID </strong></td>
<td align="left" valign="top">
<select name="selCase" id="selCase" size="1">
<option value=""> ------- Select ------ </option>
</select>
<span id="waitCase"></span>
</td>
<td><strong>Test case name</strong></td>
<td align="left" valign="top"><input type="text" name="testname" id="testname" /></td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<!-- ###################### SubCase ID #################################### -->
<tr>
<td> </td>
<td align="left" valign="top"> </td>
<td> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td width="300"><strong>Sub case ID</strong></td>
<td align="left" valign="top">
<select name="selSubcase" id="selSubcase" size="1">
<option value=""> ------- Select ------ </option>
</select><span id="waitSubcase"></span>
</td>
<td><strong>Sub case Name</strong></td>
<td align="left" valign="top">
<input type="text" name="subcasename" id="subcasename" /></td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td> </td>
<td colspan="5" align="left" valign="top"> </td>
</tr>
<tr>
<td width="300"><strong>Testing Result</strong></td>
<td colspan="5" align="left" valign="top"><textarea name="testresult" id="testresult" cols="120" rows="10"></textarea></td>
</tr>
<tr>
<td> </td>
<td align="left" valign="top"> </td>
<td> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td width="300"><strong>Result :</strong></td>
<td align="left" valign="top"><select name="result" size="1" id="result">
</select></td>
<td><strong>Tester Name :</strong></td>
<td align="left" valign="top"><input type="text" name="testname2" id="testname2" /></td>
<td align="left" valign="top"><strong>Test Date :</strong></td>
<td align="left" valign="top"><input type="text" name="date" id="date" /></td>
</tr>
<tr>
<td> </td>
<td align="left" valign="top"> </td>
<td> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td width="300"><strong>Remark</strong></td>
<td align="left" valign="top"><textarea name="testresult2" id="testresult2" cols="50" rows="10"></textarea></td>
<td><strong>Document error</strong></td>
<td align="left" valign="top"><textarea name="docerror" id="docerror" cols="50" rows="10"></textarea></td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td width="150" height="21"> </td>
<td align="left" valign="top"> </td>
<td> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td height="21" colspan="6" align="center" valign="top">
<input type="submit" name="save" id="save" value="Save" />
<input type="submit" name="edit" id="edit" value="Edit" />
<input type="submit" name="delete" id="delete" value="Delete" />
</td>
</tr>
</table>
</form>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2012-11-10 13:46:08 |
By :
NUENGCS16 |
View :
798 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถามอะไรที่มันแคบ ๆ หน่อยครับ Code เยอะเกิน ไล่ดูยากครับ
|
|
|
|
|
Date :
2012-11-10 20:59:54 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือต้องขอโทษก่อน คือกลัวไม่เข้าใจในสิ่งที่จะถามอ่ะครับ
คือ ผมไม่รู้ว่าจะเขียนโค้ดยังงัยให้สามารถแสดงชื่อของเทสเคสออกมาที่ textbox ทันที โดยอ้างอิงมาจาก case_ID ทีี่เราเลือกมาจาก
select box
|
|
|
|
|
Date :
2012-11-10 22:35:42 |
By :
NUENGCS16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|