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,038

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


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

 
Topic : 135184



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



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


ผมต้องการวนลูปArrayชุดนี้โดยการเอาข้อมูลที่queryได้มาวนลูปสร้างเลเอ้าตัวนี้ไปทำไลน์OA รบกวนใครมีึความรู้ช่วยหน่อยครับ ไม่เข้าใจArrayจริงๆ
Code (PHP)
01.$sql = "select * from product order by product_id Asc";
02.$result = $conn->query($sql);
03.$menu = [
04.        "type"=> "flex",
05.        "altText"=> "Flex Message",
06.        "contents"=> [
07.          "type"=> "carousel",
08.          "contents"=> [
09.            while($result->fetch_assoc()){
10.              [
11.                "type"=> "bubble",
12.                "hero"=> [
13.                  "type"=> "image",
14.                  "url"=> "https://www.run.ots.co.th/Medicaltour/api/".$result['product_img'],
15.                  "size"=> "full",
16.                  "aspectRatio"=> "20:13",
17.                  "aspectMode"=> "cover"
18.                ],
19.                "body"=> [
20.                  "type"=> "box",
21.                  "layout"=> "vertical",
22.                  "spacing"=> "sm",
23.                  "contents"=> [
24.                    [
25.                      "type"=> "text",
26.                      "text"=> $result['product_name'],
27.                      "size"=> "xl",
28.                      "weight"=> "bold",
29.                      "wrap"=> true
30.                    ],
31.                    [
32.                      "type"=> "box",
33.                      "layout"=> "baseline",
34.                      "flex"=> 1,
35.                      "contents"=> [
36.                        [
37.                          "type"=> "text",
38.                          "text"=> "ราคา",
39.                          "flex"=> 6,
40.                          "weight"=> "regular",
41.                          "wrap"=> true
42.                        ],
43.                        [
44.                          "type"=> "text",
45.                          "text"=> $result['product_price']" บาท",
46.                          "flex"=> 2
47.                        ]
48.                      ]
49.                    ]
50.                  ]
51.                ]
52.              ],
53.            }
54.          ]
55.        ]
56.      ];


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

Code (PHP)
01.$sql = "select * from product order by product_id Asc";
02.    $result = $conn->query($sql);
03.    $menu = [
04.            "type"=> "flex",
05.            "altText"=> "Flex Message",
06.            "contents"=> [
07.              "type"=> "carousel",
08.              "contents"=> [
09.                  [
10.                    "type"=> "bubble",
11.                    "hero"=> [
12.                      "type"=> "image",
13.                      "url"=> "https://www.run.ots.co.th/Medicaltour/api/".$result['product_img'],
14.                      "size"=> "full",
15.                      "aspectRatio"=> "20:13",
16.                      "aspectMode"=> "cover"
17.                    ],
18.                    "body"=> [
19.                      "type"=> "box",
20.                      "layout"=> "vertical",
21.                      "spacing"=> "sm",
22.                      "contents"=> [
23.                        [
24.                          "type"=> "text",
25.                          "text"=> $result['product_name'],
26.                          "size"=> "xl",
27.                          "weight"=> "bold",
28.                          "wrap"=> true
29.                        ],
30.                        [
31.                          "type"=> "box",
32.                          "layout"=> "baseline",
33.                          "flex"=> 1,
34.                          "contents"=> [
35.                            [
36.                              "type"=> "text",
37.                              "text"=> "ราคา",
38.                              "flex"=> 6,
39.                              "weight"=> "regular",
40.                              "wrap"=> true
41.                            ],
42.                            [
43.                              "type"=> "text",
44.                              "text"=> $result['product_price']" บาท",
45.                              "flex"=> 2
46.                            ]
47.                          ]
48.                        ]
49.                      ]
50.                    ]
51.                  ],
52.                  [
53.                    "type"=> "bubble",
54.                    "hero"=> [
55.                      "type"=> "image",
56.                      "url"=> "https://www.run.ots.co.th/Medicaltour/api/".$result['product_img'],
57.                      "size"=> "full",
58.                      "aspectRatio"=> "20:13",
59.                      "aspectMode"=> "cover"
60.                    ],
61.                    "body"=> [
62.                      "type"=> "box",
63.                      "layout"=> "vertical",
64.                      "spacing"=> "sm",
65.                      "contents"=> [
66.                        [
67.                          "type"=> "text",
68.                          "text"=> $result['product_name'],
69.                          "size"=> "xl",
70.                          "weight"=> "bold",
71.                          "wrap"=> true
72.                        ],
73.                        [
74.                          "type"=> "box",
75.                          "layout"=> "baseline",
76.                          "flex"=> 1,
77.                          "contents"=> [
78.                            [
79.                              "type"=> "text",
80.                              "text"=> "ราคา",
81.                              "flex"=> 6,
82.                              "weight"=> "regular",
83.                              "wrap"=> true
84.                            ],
85.                            [
86.                              "type"=> "text",
87.                              "text"=> $result['product_price']" บาท",
88.                              "flex"=> 2
89.                            ]
90.                          ]
91.                        ]
92.                      ]
93.                    ]
94.                  ],
95.                 
96.              ]
97.            ]
98.          ];




Tag : PHP, MySQL, HTML, CakePHP, FuelPHP

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

 

No. 1



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



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


Code (PHP)
01.<?php
02.function content($v1, $v2, $v3){
03.    return
04.    [   "type"=>"bubble",
05.        "hero"=>["type"=>"image","url"=>$v1,"size"=>"full","aspectRatio"=>"20:13","aspectMode"=>"cover"],
06.        "body"=>["type"=> "box","layout"=> "vertical","spacing"=> "sm",
07.            "contents"=> [
08.                ["type"=>"text", "text"=>$v2,"size"=>"xl","weight"=>"bold","wrap"=> true],
09.                ["type"=> "box","layout"=> "baseline","flex"=> 1,
10.                    "contents"=> [
11.                        ["type"=>"text", "text"=> "ราคา", "flex"=> 6, "weight"=> "regular","wrap"=> true],
12.                        ["type"=>"text", "text"=> $v3.' บาท', "flex"=> 2]
13.                    ]
14.                ]
15.            ]
16.        ]
17.    ];
18.}
19.$menu = [
20.    "type"=> "flex",
21.    "altText"=> "Flex Message",
22.    "contents"=> [
23.        "type"=> "carousel",
24.        "contents"=> []
25.    ]
26.];
27.$sql = "select * from product order by product_id Asc";
28.$result = $conn->query($sql);
29.while($ro=$result->fetch_object()){
30.    $x=content(
31.        "https://www.run.ots.co.th/Medicaltour/api/".$ro->product_img,
32.        $ro->product_name,
33.        $ro->product_price);
34.    $menu['contents']['contents'][]=$x;
35.}



ประวัติการแก้ไข
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)
01.<?php
02. 
03.// database
04.$_data = [
05.    'img' => ["image1", "image2", "image3"],
06.    'name' => ["name1", "name2", "name3"],
07.    'price' => ["price1", "price2", "price3"]
08.];
09.//print_r($_data);
10. 
11.$loop = [];
12.for ($i = 0; $i < count($_data); $i++) { // fetch_assoc()
13.    $loop[] = [ // แก้ pattern ข้อมูลซ้ำ ตามชอบ
14.        'Image' => $_data['img'][$i],
15.        'Name' => $_data['name'][$i],
16.        'Price' => $_data['price'][$i]
17.    ];
18.}
19. 
20.//print_r($loop);
21. 
22.// ประกอบร่าง array
23.$arr = [
24.    'level1' => [
25.        'level2' => $loop
26.    ]
27.];
28. 
29.print_r($arr);
30.//var_dump($arr);
31.//echo json_encode($arr);
32. 
33.?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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