Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ผมต้องการวนลูปArrayชุดนี้โดยการเอาข้อมูลที่queryได้มาวนลูปสร้างเลเอ้าตัวนี้ไปทำไลน์OA รบกวนใครมีึความรู้ช่วยหน่อยครับ ไม่เข้าใจArrayจริงๆ



 

ผมต้องการวนลูปArrayชุดนี้โดยการเอาข้อมูลที่queryได้มาวนลูปสร้างเลเอ้าตัวนี้ไปทำไลน์OA รบกวนใครมีึความรู้ช่วยหน่อยครับ ไม่เข้าใจArrayจริงๆ

 



Topic : 135184



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



ผมต้องการวนลูปArrayชุดนี้โดยการเอาข้อมูลที่queryได้มาวนลูปสร้างเลเอ้าตัวนี้ไปทำไลน์OA รบกวนใครมีึความรู้ช่วยหน่อยครับ ไม่เข้าใจArrayจริงๆ
Code (PHP)
    $sql = "select * from product order by product_id Asc";
    $result = $conn->query($sql);
    $menu = [
            "type"=> "flex",
            "altText"=> "Flex Message",
            "contents"=> [
              "type"=> "carousel",
              "contents"=> [
                while($result->fetch_assoc()){
                  [
                    "type"=> "bubble",
                    "hero"=> [
                      "type"=> "image",
                      "url"=> "https://www.run.ots.co.th/Medicaltour/api/".$result['product_img'],
                      "size"=> "full",
                      "aspectRatio"=> "20:13",
                      "aspectMode"=> "cover"
                    ],
                    "body"=> [
                      "type"=> "box",
                      "layout"=> "vertical",
                      "spacing"=> "sm",
                      "contents"=> [
                        [
                          "type"=> "text",
                          "text"=> $result['product_name'],
                          "size"=> "xl",
                          "weight"=> "bold",
                          "wrap"=> true
                        ],
                        [
                          "type"=> "box",
                          "layout"=> "baseline",
                          "flex"=> 1,
                          "contents"=> [
                            [
                              "type"=> "text",
                              "text"=> "ราคา",
                              "flex"=> 6,
                              "weight"=> "regular",
                              "wrap"=> true
                            ],
                            [
                              "type"=> "text",
                              "text"=> $result['product_price']" บาท",
                              "flex"=> 2
                            ]
                          ]
                        ]
                      ]
                    ]
                  ],
                }
              ]
            ]
          ];



อยากให้ออกมาเป็นประมาณนี้อะครับ

Code (PHP)
$sql = "select * from product order by product_id Asc";
    $result = $conn->query($sql);
    $menu = [
            "type"=> "flex",
            "altText"=> "Flex Message",
            "contents"=> [
              "type"=> "carousel",
              "contents"=> [
                  [
                    "type"=> "bubble",
                    "hero"=> [
                      "type"=> "image",
                      "url"=> "https://www.run.ots.co.th/Medicaltour/api/".$result['product_img'],
                      "size"=> "full",
                      "aspectRatio"=> "20:13",
                      "aspectMode"=> "cover"
                    ],
                    "body"=> [
                      "type"=> "box",
                      "layout"=> "vertical",
                      "spacing"=> "sm",
                      "contents"=> [
                        [
                          "type"=> "text",
                          "text"=> $result['product_name'],
                          "size"=> "xl",
                          "weight"=> "bold",
                          "wrap"=> true
                        ],
                        [
                          "type"=> "box",
                          "layout"=> "baseline",
                          "flex"=> 1,
                          "contents"=> [
                            [
                              "type"=> "text",
                              "text"=> "ราคา",
                              "flex"=> 6,
                              "weight"=> "regular",
                              "wrap"=> true
                            ],
                            [
                              "type"=> "text",
                              "text"=> $result['product_price']" บาท",
                              "flex"=> 2
                            ]
                          ]
                        ]
                      ]
                    ]
                  ],
                  [
                    "type"=> "bubble",
                    "hero"=> [
                      "type"=> "image",
                      "url"=> "https://www.run.ots.co.th/Medicaltour/api/".$result['product_img'],
                      "size"=> "full",
                      "aspectRatio"=> "20:13",
                      "aspectMode"=> "cover"
                    ],
                    "body"=> [
                      "type"=> "box",
                      "layout"=> "vertical",
                      "spacing"=> "sm",
                      "contents"=> [
                        [
                          "type"=> "text",
                          "text"=> $result['product_name'],
                          "size"=> "xl",
                          "weight"=> "bold",
                          "wrap"=> true
                        ],
                        [
                          "type"=> "box",
                          "layout"=> "baseline",
                          "flex"=> 1,
                          "contents"=> [
                            [
                              "type"=> "text",
                              "text"=> "ราคา",
                              "flex"=> 6,
                              "weight"=> "regular",
                              "wrap"=> true
                            ],
                            [
                              "type"=> "text",
                              "text"=> $result['product_price']" บาท",
                              "flex"=> 2
                            ]
                          ]
                        ]
                      ]
                    ]
                  ],
                
              ]
            ]
          ];




Tag : PHP, MySQL, HTML, CakePHP, FuelPHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2020-05-01 00:16:55 By : sukitti View : 627 Reply : 2
 

 

No. 1



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


Code (PHP)
<?php
function content($v1, $v2, $v3){
	return
	[	"type"=>"bubble",
		"hero"=>["type"=>"image","url"=>$v1,"size"=>"full","aspectRatio"=>"20:13","aspectMode"=>"cover"],
		"body"=>["type"=> "box","layout"=> "vertical","spacing"=> "sm",
			"contents"=> [
				["type"=>"text", "text"=>$v2,"size"=>"xl","weight"=>"bold","wrap"=> true],
				["type"=> "box","layout"=> "baseline","flex"=> 1,
					"contents"=> [
						["type"=>"text", "text"=> "ราคา", "flex"=> 6, "weight"=> "regular","wrap"=> true],
						["type"=>"text", "text"=> $v3.' บาท', "flex"=> 2]
					]
				]
			]
		]
	];
}
$menu = [
	"type"=> "flex",
	"altText"=> "Flex Message",
	"contents"=> [
		"type"=> "carousel",
		"contents"=> []
	]
];
$sql = "select * from product order by product_id Asc";
$result = $conn->query($sql);
while($ro=$result->fetch_object()){
	$x=content(
		"https://www.run.ots.co.th/Medicaltour/api/".$ro->product_img,
		$ro->product_name,
		$ro->product_price);
	$menu['contents']['contents'][]=$x;
}










ประวัติการแก้ไข
2020-05-01 14:24:05
2020-05-01 18:46:17
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-05-01 14:23:41 By : Chaidhanan
 


 

No. 2



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

รับทองไปแล้ว...มาลองศึกษาพื้นดินบ้าง
(เฉพาะ array)

Code (PHP)
<?php

// database
$_data = [
	'img' => ["image1", "image2", "image3"],
    'name' => ["name1", "name2", "name3"],
    'price' => ["price1", "price2", "price3"]
];
//print_r($_data);

$loop = [];
for ($i = 0; $i < count($_data); $i++) { // fetch_assoc()
	$loop[] = [ // แก้ pattern ข้อมูลซ้ำ ตามชอบ
    	'Image' => $_data['img'][$i],
        'Name' => $_data['name'][$i],
        'Price' => $_data['price'][$i]
    ];
}

//print_r($loop);

// ประกอบร่าง array
$arr = [
	'level1' => [
    	'level2' => $loop
    ]
];

print_r($arr);
//var_dump($arr);
//echo json_encode($arr);

?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-05-01 15:14:53 By : PhrayaDev
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ผมต้องการวนลูปArrayชุดนี้โดยการเอาข้อมูลที่queryได้มาวนลูปสร้างเลเอ้าตัวนี้ไปทำไลน์OA รบกวนใครมีึความรู้ช่วยหน่อยครับ ไม่เข้าใจArrayจริงๆ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่