EasyUI Forum
May 06, 2024, 09:04:18 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Poll
Question: exchange combobox data between 2 php with datagrid
combobox - 0 (0%)
php - 0 (0%)
Total Voters: 0

Pages: [1]
  Print  
Author Topic: exchange combobox data between 2 php with datagrid  (Read 22258 times)
simonlkch
Newbie
*
Posts: 6


View Profile Email
« on: March 03, 2014, 09:01:56 PM »

base on the "Build CRUD Application with jQuery EasyUI" tur
http://www.jeasyui.com/tutorial/app/crud.php

I write it by php

i would like to exchange data by by the combobox

for example

when i add a new user

i will enter the "item type", and the "item type" is come from the "item type number"

here is my database

userType itemTypeNumber
water      01
rice  02
noodle   03

when i choose the water with combobox , return value should be 01

then i use a sql command -  insert into mydatabase(typeno) value '$typeno' ;
---------------

I can get the $typeno in index.php
but can not get $typeno in add_item.php


This is index.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php
include 'conn.php';
    
 $sql_type "SELECT * FROM type"//special offer
$rows_type mysql_query($sql_type); //執行SQL查詢
$num_type mysql_num_rows($rows_type); //取得記錄


?>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description" content="easyui help you build your web page easily!">
<title>jQuery EasyUI CRUD Demo</title>
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
<style type="text/css">
#fm{
margin:0;
padding:10px 30px;
}
.ftitle{
font-size:14px;
font-weight:bold;
color:#666;
padding:5px 0;
margin-bottom:10px;
border-bottom:1px solid #ccc;
}
.fitem{
margin-bottom:5px;
}
.fitem label{
display:inline-block;
width:80px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
var url;
function addItem(){
$('#dlg').dialog('open').dialog('setTitle','新增項目');
$('#fm').form('clear');
url = 'add_item.php';
}
function editUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$('#dlg').dialog('open').dialog('setTitle','修改項目');
$('#fm').form('load',row);
url = 'update_user.php?id='+row.id;
}
}
function saveItem(){
$('#fm').form('submit',{
url: url,
onSubmit: function(){
return $(this).form('validate');
},
success: function(result){
var result = eval('('+result+')');
if (result.success){
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({
title: 'Error',
msg: result.msg
});
}
}
});
}
function removeUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('Confirm','Are you sure you want to remove this user?',function(r){
if (r){
$.post('remove_user.php',{id:row.id},function(result){
if (result.success){
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.msg
});
}
},'json');
}
});
}
}
</script>
</head>
<body>
<h2>Basic CRUD Application</h2>
<div class="demo-info" style="margin-bottom:10px">
<div class="demo-tip icon-tip">&nbsp;</div>
<div>Click the buttons on datagrid toolbar to do crud actions.</div>
</div>

<table id="dg" title="項目" class="easyui-datagrid" style="width:700px;height:400px"
url="get_item.php"
toolbar="#toolbar" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="itemno" width="50">項目編號</th>
<th field="itemname" width="50">項目名稱</th>
<th field="typeno" width="50">類型編號</th>
<th field="price" width="50">價錢</th>
<th field="stocklevel" width="50">存貨</th>
</tr>
</thead>
</table>
<div id="toolbar">
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addItem()">新增項目</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改項目</a>
<!--<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeUser()">Remove User</a>-->
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:300px;padding:10px 20px"
closed="true" buttons="#dlg-buttons">
<div class="ftitle">項目資料</div>
<form id="fm" method="post" >
<div class="fitem">
<label>項目編號:</label>
<input name="itemno" class="easyui-validatebox" >
</div>
<div class="fitem">
<label>項目名稱:</label>
<input name="itemname" class="easyui-validatebox" required="true">
</div>
<div class="fitem">
<label>類型編號:</label>
<select class="easyui-combobox" name="typename" style="width:200px;">
    
     <?php
if ($num_type>0){ //if有記錄
for ($i 0;$i $num_type$i++){
$typeno mysql_result($rows_type$i"typeno");
$typename mysql_result($rows_type$i"typename");
echo $typeno;
echo "<option value='$typeno'>$typename</option>";
}
}
?>

  </select>
</div>
<div class="fitem">
<label>價錢:</label>
<input name="price" class="easyui-validatebox" required="true">
</div>
<div class="fitem">
<label>存貨:</label>
<input name="stocklevel" class="easyui-validatebox" required="true">
</div>
</form>
</div>
<div id="dlg-buttons">
<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveItem()">儲存</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
</body>
</html>

This is add_item.php

Code:
<?php

//$itemno = $_REQUEST['itemno'];
$itemname $_REQUEST['itemname'];
$typeno $_REQUEST['typeno'];
$price $_REQUEST['price'];
$stocklevel $_REQUEST['stocklevel'];



include 
'conn.php';

$sql "insert into item(itemno,itemname,typeno,price,stocklevel) values('null','$itemname','$typeno','$price','$stocklevel')";

$result = @mysql_query($sql);
if (
$result){
echo json_encode(array('success'=>true));
} else {
echo json_encode(array('msg'=>'wrong.'));
}
?>
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 04, 2014, 12:48:07 AM »

You are defining the following code for your field.
Code:
<select class="easyui-combobox" name="typename" style="width:200px;">
...
</select>

Notice that the element's name attribute value is 'typename', this is why you can't get 'typeno' value by $_REQUEST['typeno']. To solve this issue, please modify the element's name to 'typeno'.
Code:
<select class="easyui-combobox" name="typeno" style="width:200px;">
...
</select>
Logged
simonlkch
Newbie
*
Posts: 6


View Profile Email
« Reply #2 on: March 04, 2014, 09:35:51 AM »

You are defining the following code for your field.
Code:
<select class="easyui-combobox" name="typename" style="width:200px;">
...
</select>

Notice that the element's name attribute value is 'typename', this is why you can't get 'typeno' value by $_REQUEST['typeno']. To solve this issue, please modify the element's name to 'typeno'.
Code:
<select class="easyui-combobox" name="typeno" style="width:200px;">
...
</select>


thank you!! you solve my problem
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!