yatyao
05-06-2010, 11:13
Mình xây dựng 1 component tên là hientrang có 2 file php như sau:
hientrang.php
<?php
defined('_JEXEC') or die('Restricted access');
require_once (dirname(__FILE__).DS.'htphp.php');
$fastMessage = hientrang::addht($params);
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__dangky ORDER BY #__dangky.giodk";
$db->setQuery( $query );
$result = $db->query();
$user =& JFactory::getUser();
$usr_id = $user->get('id');
$dbx =& JFactory::getDBO();
$q1 = "SELECT * FROM #__users WHERE id = $usr_id";
$dbx->setQuery( $q1 );
$resultx = $dbx->query();
$ry = mysql_fetch_array ($resultx);
?>
<script language="javascript">
function getdetail()
{
document.hientrang.submit();
}
</script>
<div id="addhientrangForm">
<form ...
<select name="trangthai" onchange="getdetail()" >
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="Not">Not</option>
</select>
</td>
..
</form>
</div>
và trang htphp.php
<?php
defined('_JEXEC') or die('Restricted access');
//require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'h elpers'.DS.'route.php');
class hientrang
{
function addht($params)
{
$db =& JFactory::getDBO();
$trangthai = JRequest::getVar('trangthai', 'Not Given', 'POST');
$check = JRequest::getVar('check', 'Not Given', 'POST');
echo "$trangthai </br>";
echo "$check";
$query = "UPDATE #__dangky SET trangthai = $trangthai WHERE Madk = $check";
$db->setQuery($query);
$result = $db->query();
}
}
?>
ban đầu trang hientrang.php sẽ được gọi lên, sau đó truyền tham số trả về cho trang htphp.php. Vấn đề ở đây là chỗ select mình đã truyền tham số qua được, nhưng nó chỉ nhận mỗi value Yes mà thôi!, mình mỗi khi chọn 1 option thì sẽ ra 1 value tương ứng!
MOng các bạn xem giúp dùm mình! Chân thành cảm ơn!
hientrang.php
<?php
defined('_JEXEC') or die('Restricted access');
require_once (dirname(__FILE__).DS.'htphp.php');
$fastMessage = hientrang::addht($params);
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__dangky ORDER BY #__dangky.giodk";
$db->setQuery( $query );
$result = $db->query();
$user =& JFactory::getUser();
$usr_id = $user->get('id');
$dbx =& JFactory::getDBO();
$q1 = "SELECT * FROM #__users WHERE id = $usr_id";
$dbx->setQuery( $q1 );
$resultx = $dbx->query();
$ry = mysql_fetch_array ($resultx);
?>
<script language="javascript">
function getdetail()
{
document.hientrang.submit();
}
</script>
<div id="addhientrangForm">
<form ...
<select name="trangthai" onchange="getdetail()" >
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="Not">Not</option>
</select>
</td>
..
</form>
</div>
và trang htphp.php
<?php
defined('_JEXEC') or die('Restricted access');
//require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'h elpers'.DS.'route.php');
class hientrang
{
function addht($params)
{
$db =& JFactory::getDBO();
$trangthai = JRequest::getVar('trangthai', 'Not Given', 'POST');
$check = JRequest::getVar('check', 'Not Given', 'POST');
echo "$trangthai </br>";
echo "$check";
$query = "UPDATE #__dangky SET trangthai = $trangthai WHERE Madk = $check";
$db->setQuery($query);
$result = $db->query();
}
}
?>
ban đầu trang hientrang.php sẽ được gọi lên, sau đó truyền tham số trả về cho trang htphp.php. Vấn đề ở đây là chỗ select mình đã truyền tham số qua được, nhưng nó chỉ nhận mỗi value Yes mà thôi!, mình mỗi khi chọn 1 option thì sẽ ra 1 value tương ứng!
MOng các bạn xem giúp dùm mình! Chân thành cảm ơn!