2013-01-22 20 views
6

के साथ एकाधिक तालिकाओं में से चुनें मैं Laravel के साथ काम करने के लिए कुछ PHP/MySQL पुनः लिख रहा हूं।लारवेल धाराप्रवाह क्वेरी बिल्डर

SELECT p.post_text, p.bbcode_uid, u.username, t.forum_id, t.topic_title, t.topic_time, t.topic_id, t.topic_poster 
FROM phpbb_topics t, phpbb_posts p, phpbb_users u 
WHERE t.forum_id = 9 
AND p.post_id = t.topic_first_post_id 
AND u.user_id = t.topic_poster 
ORDER BY t.topic_time 
DESC LIMIT 10 

यह एक phpBB मंच प्रश्नों और पदों हो जाता है: enter image description here

मैं कैसे फिर से हो सकता है एक बात मैं करना चाहते हैं डीबी अधिक संक्षिप्त with the Fluent Query Builder प्रश्नों लेकिन मैं थोड़ा खो कर रहा हूँ कर रहा है Fluent क्वेरी बिल्डर वाक्यविन्यास का उपयोग करने के लिए इसे लिखें?

उत्तर

18

जांची नहीं, लेकिन यहाँ एक शुरुआत

return DB::table('phpbb_topics') 
         ->join('phpbb_posts', 'phpbb_topics.topic_first_post_id', '=', 'phpbb_posts.post_id') 
         ->join('phpbb_users', 'phpbb_topics.topic_poster', '=', 'phpbb_users.user_id') 
         ->order_by('topic_time', 'desc') 
         ->take(10) 
         ->get(array(

            'post_text', 
            'bbcode_uid', 
            'username', 
            'forum_id', 
            'topic_title', 
            'topic_time', 
            'topic_id', 
            'topic_poster' 


         )); 
+0

आह, पता नहीं था आप श्रृंखला में शामिल कर सकता है। उपयोगी, धन्यवाद। - - –

+0

(5.3 में परीक्षण) के नीचे जैसा कोई विकल्प नहीं है> सरणी (प्राप्त ('। Phpbb_topics *', 'उपयोगकर्ता नाम', नहीं बोल अंग्रेजी के लिए 'phpbb_posts.post_text' ) – Sadat

2

इस कोड को प्रयास करने पर विचार है। इसे पूरा करना चाहिए जो आपको पूरा करना है।

DB::select(DB::raw("SELECT p.post_text, p.bbcode_uid, u.username, t.forum_id, t.topic_title, t.topic_time, t.topic_id, t.topic_poster 
FROM phpbb_topics t, phpbb_posts p, phpbb_users u 
WHERE t.forum_id = 9 
AND p.post_id = t.topic_first_post_id 
AND u.user_id = t.topic_poster 
ORDER BY t.topic_time 
DESC LIMIT 10")); 
+1

, आप का निदान किया है लग रहा था समस्या ठीक है: पी – rayryeng

1
return DB::table(DB::raw('phpbb_topics t, phpbb_posts p, phpbb_users u')) -> select(DB::raw('p.post_text, p.bbcode_uid, u.username, t.forum_id, t.topic_title, t.topic_time, t.topic_id, t.topic_poster'))->where('phpbb_topics.topic_first_post_id', '=', 'phpbb_posts.post_id')->where('phpbb_users', 'phpbb_topics.topic_poster', '=', 'phpbb_users.user_id')->order_by('topic_time', 'desc')->take(10)->get(); 
संबंधित मुद्दे