วิธีการใส่คำสั่ง Where in อย่างไรครับใน Joomla

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: วิธีการใส่คำสั่ง Where in อย่างไรครับใน Joomla

Re: วิธีการใส่คำสั่ง Where in อย่างไรครับใน Joomla

โดย Patipat » 13/07/2019 7:15 pm

ได้แล้วครับผม ขอบคุณมากๆ ครับ

Re: วิธีการใส่คำสั่ง Where in อย่างไรครับใน Joomla

โดย thatsawan » 13/07/2019 6:53 pm

โค้ด: เลือกทั้งหมด

   
public function newItem($product_slisdershow)
     {
           $db = Joomla\CMS\Factory::getDbo();
           $query = $db ->getQuery(true)
                        ->select('a.category_id, b.product_id, b.image ,b.product_price,'.$db->qn('name_en-GB'))
                        ->from('#__mzc_products as b')
                        ->where('product_id in (1,2)');
                        ->leftJoin('#__mzc_products_to_categories AS a ON b.product_id = a.product_id')   
                        ->order('product_id DESC');
                        $db->setQuery($query,0,$product_slisdershow);

           $items = $db ->loadAssocList();
           return $items;
        }
การดูคำสั่ง sql ใน joomla
https://www.mindphp.com/forums/viewtopic ... 42&t=48427

วิธีการใส่คำสั่ง Where in อย่างไรครับใน Joomla

โดย Patipat » 13/07/2019 6:49 pm

คือผมแปลงโค้ดจาก sql จะใส่คำสั่ง Where in ใน Joomla ได้อย่างไรครับ จากโค้ดนี้ครับ ต้องการจะเลือก id สินค้ามากกว่าหนึ่ง

โค้ด: เลือกทั้งหมด

SELECT * FROM `products` where product_id IN (2,3) 
**สิ่งที่ต้องการคือ จะใส่ Where in อย่างไรครับ
ส่วนตรงนี้โค้ด Joomla ครับ

โค้ด: เลือกทั้งหมด

   
public function newItem($product_slisdershow)
     {
           $db = Joomla\CMS\Factory::getDbo();
           $query = $db ->getQuery(true)
                        ->select('a.category_id, b.product_id, b.image ,b.product_price,'.$db->qn('name_en-GB'))
                        ->from('#__mzc_products as b')
                        ->leftJoin('#__mzc_products_to_categories AS a ON b.product_id = a.product_id')   
                        ->order('product_id DESC');
                        $db->setQuery($query,0,$product_slisdershow);

           $items = $db ->loadAssocList();
           return $items;
        }

ข้างบน