【发布时间】:2011-09-02 19:55:09
【问题描述】:
问题
现在我必须创建这个:
在我的数据库中;每个收藏夹都有自己的“权重”条目。
截至目前,它默认为“10”
假设我有一系列收藏夹,
相应的权重是这样的:
- 1
- 2
- 3
- 4
如果我要按“2”上的“向下”箭头,我必须为其权重加上 +1。
这将导致:
- 1
- 3
- 3
- 4
但我只想用最喜欢的 '3' 的重量切换最喜欢的 '2'。
我需要一种方法来确保当每个项目的权重按隐含的方式发挥作用时。
因为只是加或减1会导致很多问题。
希望我解释得当。
代码
写入数据库
/*
* Write Form data to database
*/
function f25_favorites_form_submit($form, &$form_state){
global $user;
$listOfPaths = f25_favorites_listOfPaths();
$selected = $form_state['values']['path'];
$data = array(
'uid' => $user->uid,
'path' => $selected,
'title' => $listOfPaths[$selected]['#title'],
'weight' => 10,
'timestamp' => time(),
);
drupal_write_record(f25_favorites, $data);
}
查询
/*
* Fetching Specific User's Favorites Data
*/
function f25_favorites_user_favorites() {
global $user;
if($user->uid > 0){
$userid = $user->uid;
$user_paths = db_query("SELECT * FROM f25_favorites foo WHERE foo.uid = '%s' ORDER BY foo.weight DESC", $userid);
$pathlist = array();
while ($data = db_fetch_object($user_paths)) {
$pathlist[] = $data;
}
return $pathlist;
}
}
我应该如何解决这个问题?
【问题讨论】:
标签: php mysql arrays drupal-6 drupal-modules