2013-12-15 11 views
0

我userlisting提供鏈接編輯用戶和更新配置文件時,一個點擊,然後它去更新個人資料視圖與相應用戶的ID的用戶的屏幕名稱爲:我的CodeIgniter控制器與id一起作爲參數傳遞,只是一直使用一個特定的id?

//url: 
    localhost/damcombd/admin/userprofile/userupdate/3 

形式加載好的和地址欄並在鼠標懸停狀態欄上都顯示鏈接如上 但實際上在控制器中,如果我拉這個ID的東西說來自用戶模型,它只是去第一個記錄或ID 1 ..並一直這樣做。儘可能地嘗試!

可能是什麼原因?檢查是否有硬編碼的ID太..但是這並非如此..

//with this one too I create a row and get it back like: 
    $this->commonmodel->create_and_get($table,$data){ 
     $this->db->insert($table,$data); 
     $lastid=$this->db->insert_id(); 
     $getback=$this->db->get($table,array('id'=>$lastid))->result_array(); 
     return $getback[0]; 

但它返回每一次的第一行..我不知道像USERPROFILE更新上述這其中也拉屎各地..它是錯誤或something..I不要在all..try得到它,因爲我可能:(:(請做一些事情..

回答

0

當我用

$this->db->get_where($table,array('id'=>$lastid)); 
    //actually for get the above line would have been false syntax.. 

我提到的第二個問題是解決了,我想我會我想下一個出過...

我的第一個問題是過於解決......其實,準確的方式.. 來形容它一下,讓一些人們可能會幫助..

//If u use 
    $obj=$this->db->get($table,array('id'=>$lastid))->result_array(); //here then 
    // it will actually do a simple get all operation and returning: 
    return $obj[0] //will obviously return the very first row..try as u might. 
    //so for querying with id always use: 
    $this->db->get_where(); 
+0

我認爲你可以使用 - > row_array()而不是 - > result_array()來獲取第一行。以防萬一你沒有這樣做,閱讀手冊與此選擇http://ellislab.com/codeigniter/user-guide/database/active_record.html#select和更重要的是,獲取結果:http:// ellislab.com/codeigniter/user-guide/database/results.html – Chococroc

+0

是啊你說的對..我讀過它。謝謝 – edam

0

這可能是因爲:

一)在你的路由你指定的ID它是所有的時間:

b)您的控制器是一個錯誤的編號

c)您的模型正在執行錯誤的查詢。

我會做什麼:請您在路線applocation /配置/路由的句子

$routes['admin/userprofile/userupdate/(:num)'] = 'admin/userprofile/userupdate/$1' 

也許你的1,之前忘了$,P。

然後,在收到POST/GET值後檢查您發送的值,確定是正確的ID,打印它並檢查此值是否爲預期值(您正在編輯用戶2,如此你得到id 2等等)。

如果該值是正確的,請檢查從數據庫中檢索到什麼。在您的模型中,您可以編寫:

echo $this->db->last_query(); 

並檢查SQL查詢執行的是什麼。只是做我寫你在上面,並告訴我們發生了什麼,:d

+0

無兄弟,我的路由未配置爲用戶個人資料..嗯,我認爲這可能是一些微妙的陷阱或一個錯誤..你可以告訴任何更多? – edam

相關問題