1
使用拖放系統在joomla內部訂購商品。 從數據庫獲取項目不成問題。 我做這個用下面的代碼Joomla 3更新dabatase
`<script type="text/javascript">
$(document).ready(function(){
$(function() {
$("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("templates/sorteren/test/updateDB.php", order, function(theResponse){
$("#contentRight").html(theResponse);
});
}
});
});
});
</script>
<?php
$db = & JFactory::getDBO();
$query = $db->getQuery(true)
->select('a.title, a.id, a.sorteren')
->from('#__k2_items as a')
->where('a.created_by =' . $user->id . ' and a.trash = 0')
->order('a.sorteren');
$db->setQuery($query);
$items = $db->loadObjectList();
foreach($items as $item) {
echo '<li id="recordsArray_' . $item->id . '">' . $item->title . '';
}?>`
但問題是,在下面的代碼的地方,但我不能沒有弄清楚這個問題可能是什麼
<?php defined('_JEXEC') or die;
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray = $_POST['recordsArray'];
if ($action == "updateRecordsListings"){
$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {
$query = "UPDATE #__k2_items SET sorteren = " . $listingCounter . " WHERE id = " . $recordIDValue;
$db->setQuery($query);
$db->query();
$listingCounter = $listingCounter + 1;
}
echo '<pre>';
print_r($updateRecordsArray);
echo '</pre>';
echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>
有沒有誰可以推我在好的方向? 將是巨大的:)
UPDATE:
我用這個外面的Joomla和它的作品
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(function() {
$("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("updateDB.php", order, function(theResponse){
$("#contentRight").html(theResponse);
});
}
});
});
});
</script>
<div id="contentLeft">
<ul>
<?php
$query = "SELECT * FROM kxmkw_k2_items WHERE created_by = 1000 AND trash = 0 ORDER BY sorteren ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<li id="recordsArray_<?php echo $row['id']; ?>"><?php echo $row['title'] . "<br> " . $row['id']; ?></li>
<?php } ?>
</ul>
</div>
內的Joomla我用這個
<script type="text/javascript">
$(document).ready(function(){
$(function() {
$("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("templates/sorteren/test/updateDB.php", order, function(theResponse){
$("#contentRight").html(theResponse);
});
}
});
});
});
</script>
<?php
$db = & JFactory::getDBO();
$query = $db->getQuery(true)
->select('a.title, a.id, a.sorteren')
->from('#__k2_items as a')
->where('a.created_by =' . $user->id . ' and a.trash = 0')
->order('a.sorteren');
$db->setQuery($query);
$items = $db->loadObjectList();
foreach($items as $item) {
echo '<li id="recordsArray_' . $item->id . '">' . $item->title . '';
}?>
任何想法?
Lodder, 謝謝您的快速答覆和解釋,但這也沒有更新數據庫。 – user3021953
@ user3021953 - 查看我的更新回答 – Lodder
如果我添加var_dump,它會給我返回null null。外joomla它正在工作,但在joomla裏面,它出錯了。對我有更多提示? :)乾杯\ – user3021953