มีใครเขียนตารางแบบใช้ 2 loop หรอว่า while เป็นบ้างครับ

เริ่มโดย gusstrawberry, 14 ตุลาคม 2012, 11:17:18

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

gusstrawberry

อยากได้ตัวอย่างการเขียน Table แบบ 2 loop ครับ หรอว่าจะใช้ while ก็ได้ครับ
PHP , Javascript อันไหนก็ได้ครับ
ให้มันเรียงแบบนี้ ขอบคุณมากครับ

array = ["A",1,"C","D","E","F","G",2,3];

[A][1][C]
[D][E][F]
[G][2][3]

:wanwan017:

xvlnw.com

[A][1][C]
[D][E][F]
[G][2][3]

แบบนี้ต้องเป็น Array แบบ 2 มิติครับ


<?php
$data 
= array(
array(
'A',1,'C'),
array(
'D','E','F'),
array(
'G',2,3)
);
?>



วิธีแสดงผลก็


<?php
foreach($data as $one){
   foreach(
$one as $two){
    echo 
'[',$two,']';
  }
  echo 
'<br>';

?>

[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

muay5157

จัดไปครับ


<?php 

$string 
= array ("A",1,"C","D","E","F","G",2,3);
$x 1;
?>

<table border="1">
 <tr>
  <?php
     
foreach($string as $key)
      {

   echo "<td>" $key "</td>";
     if($x == 0)
      {
echo "</tr><tr>";
      }
   $x++;
      }
?>

 </tr>
</table>
:wanwan011:


ผิดวัตถุประสงค์นิดนึง แต่ผมว่า foerach ดีกว่า while ครับ ถ้าใช้กับ array  ^_^ ถ้าอยากได้ while จริง บอกก็ได้ครับ เด่วเขียนให้
mesati.com ประกาศงานศพออนไลน์ เว็บไซต์[direct=http://www.mesati.com]งานศพ[/direct] และ
[direct=http://www.mesati.com]พวงหรีด[/direct] ที่ไฮเทคที่สุดในประเทศ (รางวัลจาก TICTA AWARDS 2011)

|[direct=http://www.ptt.co.th]ตู้สาขาโทรศัพท์[/direct]
|[direct=http://www.ptt.co.th]กล้องวงจรปิด[/direct]

gusstrawberry

ขอบคุณครับ ถ้าติดตรงไหนเดี๋ยวผมจะกลับมาถามใหม่ครับ