 |
[PHP]
ผมต้องการวนลูปArrayชุดนี้โดยการเอาข้อมูลที่queryได้มาวนลูปสร้างเลเอ้าตัวนี้ไปทำไลน์OA รบกวนใครมีึความรู้ช่วยหน่อยครับ ไม่เข้าใจArrayจริงๆ |
|
 |
|
|
 |
 |
|
ผมต้องการวนลูป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" ,
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" ,
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" ,
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
|
|
 |
 |
 |
 |
Date :
2020-05-01 00:16:55 |
By :
sukitti |
View :
795 |
Reply :
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(
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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รับทองไปแล้ว...มาลองศึกษาพื้นดินบ้าง
(เฉพาะ array)
Code (PHP)
01. <?php
02.
03.
04. $_data = [
05. 'img' => [ "image1" , "image2" , "image3" ],
06. 'name' => [ "name1" , "name2" , "name3" ],
07. 'price' => [ "price1" , "price2" , "price3" ]
08. ];
09.
10.
11. $loop = [];
12. for ( $i = 0; $i < count ( $_data ); $i ++) {
13. $loop [] = [
14. 'Image' => $_data [ 'img' ][ $i ],
15. 'Name' => $_data [ 'name' ][ $i ],
16. 'Price' => $_data [ 'price' ][ $i ]
17. ];
18. }
19.
20.
21.
22.
23. $arr = [
24. 'level1' => [
25. 'level2' => $loop
26. ]
27. ];
28.
29. print_r( $arr );
30.
31.
32.
33. ?>
|
 |
 |
 |
 |
Date :
2020-05-01 15:14:53 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|