เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

ตอบกระทู้

รูปแสดงอารมณ์
: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] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

Re: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย tsukasaz » 23/07/2019 5:07 pm

tsukasaz เขียน:ใช้คำสั่ง implode ไงครับ https://www.mindphp.com/%E0%B8%84%E0%B8 ... plode.html

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

implode(',', $product_slisdershow)
ก็ Copy Code แล้วเอาวางแทนที่ตัวแปรสิครับ

Re: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย Patipat » 23/07/2019 4:51 pm

tsukasaz เขียน:มัน Error ก่อนที่จะ print ค่าแล้วครับ

แล้วคำถามที่ว่าจะใส่ค่า ที่แปลงมาจาก array คือจะเอาค่าไปใส่ตรงไหนของ Code หรอครับ
ผมจะนำไปใส่ไว้ตรงนี้ครับ เปลี่ยนจาก $product_slisdershow เป็นตัวแปรที่แปลงมาครับ

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

->where('a.product_id in ('.$product_slisdershow.')') 

Re: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย Patipat » 23/07/2019 4:49 pm

thatsawan เขียน:จะแก้ไขปัญหาได้ ต้องรู้ว่า error ที่ไหน เช็คเเต่ละบรรทัดก่อนว่าเป็นที่ไหน

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

$product_slisdershow = $params->get('selectid'); 
$setid = implode(",", $product_slisdershow);
print_r($setid);
exit();

ครับผมตอนนี้ get ค่าออกมาได้แล้วครับ
แต่ว่า ยังเออเร่อตอน select ข้อมูลครับ
Selection_999(377).png
Selection_999(377).png (50.76 KiB) Viewed 587 times

Re: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย tsukasaz » 23/07/2019 4:43 pm

มัน Error ก่อนที่จะ print ค่าแล้วครับ

แล้วคำถามที่ว่าจะใส่ค่า ที่แปลงมาจาก array คือจะเอาค่าไปใส่ตรงไหนของ Code หรอครับ

Re: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย thatsawan » 23/07/2019 4:41 pm

จะแก้ไขปัญหาได้ ต้องรู้ว่า error ที่ไหน เช็คเเต่ละบรรทัดก่อนว่าเป็นที่ไหน

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

$product_slisdershow = $params->get('selectid'); 
$setid = implode(",", $product_slisdershow);
print_r($setid);
exit();

Re: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย Patipat » 23/07/2019 4:23 pm

พอมผม ใส่ ให้เท่ากับตัวแปรนี้ มัน ขึ้นเออเร่อครับ เช็คค่าไม่ได้

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

$product_slisdershow = $helper_newproduct->newItem($params->get('selectid')); 
$setid = implode(",", $product_slisdershow);
print_r($setid);
exit();

 
Selection_999(376).png
Selection_999(376).png (8.79 KiB) Viewed 596 times

Re: เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย tsukasaz » 23/07/2019 4:09 pm

ใช้คำสั่ง implode ไงครับ https://www.mindphp.com/%E0%B8%84%E0%B8 ... plode.html

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

implode(',', $product_slisdershow) 

เรามีวิธีการ ใส่ค่า ที่เราแปลงมาจาก Array อย่างไรครับ

โดย Patipat » 23/07/2019 4:01 pm

โค้ดที่จะนำค่า ไปแสดงข้อมูลครับ แต่ว่า ตรง ->where('a.product_id in ('.$product_slisdershow.')') ข้อมูล ต้องเป็น เช่น 1,2,3,4 ถึงจะแสดงข้อมูลได้
แต่ว่า ผม แปลงค่าจาก Arary มาแล้ว มันนำไปใส่ไม่ได้ครับ ต้องใส่ตรงไหนถึงจะถูกหลักครับ โค้ดที่แปลงมาคือเป็นตัวแปร $setid ครับ
พอเช็คค่า $setid ดูก็จะได้ 1,2,3,4 ครับแต่ว่า นำไปใส่ใน Where ไมไ่ด้ครับ

โค้ดที่ดึงค่าจาก Fields ครับ

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

$helper_newproduct = new ModShowProductNewItem();
$product_slisdershow = $helper_newproduct->newItem($params->get('selectid')); 


โค้ดของคลาสแสดงข้อมูลครับ

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

class ModShowProductNewItem
   {
        public function newItem($product_slisdershow)
        {
         $lang_tag = \Joomla\CMS\Factory::getLanguage()->getTag(); 
           $db = Joomla\CMS\Factory::getDbo();
           $query = $db ->getQuery(true)
           
                      
                        ->select('a.category_id, b.product_id, b.image ,b.product_price,'.$db->qn('b.name_'.$lang_tag))
                        ->from('#__mzc_products as b')
                        ->where('a.product_id in ('.$product_slisdershow.')')
                        ->leftJoin('#__mzc_products_to_categories AS a ON b.product_id = a.product_id')   
                        ->order('product_id DESC');
                        $db->setQuery($query,0,$product_slisdershow);
                        
                        
                        //ตัวที่แปลงมาจาก Array 
                        $setid = implode(",", $product_slisdershow);
                        echo $setid;
                        exit();
                     
            
           $items = $db ->loadAssocList();
           return $items;
        } 

ข้างบน