มีปัญหาเกี่ยวกับ การแสดงผล ของ 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 ครับ

โดย mysuerte » 20/10/2011 12:26 am

พอมี code ตัวอย่าง หรือเปล่าครับ จะได้ลองแกะครับ

ตอนนี้กำลังศึกษาแต่ก็ยังมึนๆ - -*

Re: มีปัญหาเกี่ยวกับ การแสดงผล ของ array ครับ

โดย mindphp » 19/10/2011 12:40 pm

แนะนำวิธีศีกษา
- ทำความเข้าใจ ส่วนประกอบ tag <table>,<tr>,<td>
- function list()
https://www.mindphp.com/modules.php?name ... .list.html
- function each()
https://www.mindphp.com/modules.php?name ... .each.html

ลองหัดเขียน tag แต่ละ tag ดูครับ แล้วค่อยเอาเรื่อง array เข้ามาร่วม

Re: มีปัญหาเกี่ยวกับ การแสดงผล ของ array ครับ

โดย mysuerte » 19/10/2011 12:05 pm

ต้องแก้ตรงไหน ไฟล์ไหน บ้างอะครับ
พี่ช่วย เขียน code ตรงที่ต้องแก้ ให้หน่อยได้ป่าวครับ

ตอนนี้มึนไปหมดแล้ว
พอดีมือใหม่มากๆ พึ่งเรียน ถึง array อยู่เลย

ขอบคุณมากๆนะครับที่ช่วยตอบ

Re: มีปัญหาเกี่ยวกับ การแสดงผล ของ array ครับ

โดย mindphp » 19/10/2011 11:53 am

นับ array ทั้งหมด แล้วหารปัดเศษขึ้น ด้วยจำนวนรูปในหนึ่งแล้ว
เพื่อสร้าง <tr>...</tr>
แล้วใช้ list() คู่กับ each() ลงไปในแต่ละ <td>...</td>
ถ้าใช้ table แนวคิดประมาณนี้ครับ

Re: มีปัญหาเกี่ยวกับ การแสดงผล ของ array ครับ

โดย mysuerte » 19/10/2011 7:35 am

ผมแก้ รูปแล้วนะครับ

ขอบคุณทุกท่านที่ตอบนะ

Re: มีปัญหาเกี่ยวกับ การแสดงผล ของ array ครับ

โดย mindphp » 19/10/2011 2:01 am

ภาพไม่ขึ้นครับ โพสภาพ กรุณาอย่าใช้เว็บฝากไฟล์
อัพโหลดมาที่เว็บบอร์ดโดยตรง

มีปัญหาเกี่ยวกับ การแสดงผล ของ array ครับ

โดย mysuerte » 18/10/2011 10:53 pm

ภาพไฟล์ทั้งหมด
รูป1
รูป1
1.jpg (28.17 KiB) Viewed 7624 times
คือตอนแรก ผม สร้างไฟล์ mkv.inc.php อันนี้คือ code ครับ

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

<style type="text/css">
a:link {
	font-family: Tahoma, Geneva, sans-serif;
	color: #7a7a7a;
	font-size: 12px;
	text-decoration: none;
}
a:hover {
	font-family: Tahoma, Geneva, sans-serif;
	color: #fc417a;
	font-size: 12px;
	text-decoration: none;
}
a:visited {
	font-family: Tahoma, Geneva, sans-serif;
	color: #7a7a7a;
	font-size: 12px;
	text-decoration: none;
}
a:active {
	font-family: Tahoma, Geneva, sans-serif;
	color: #ed51a9;
	font-size: 12px;
	text-decoration: none;
}
</style>

<?php
function testOne(){
$quotes = array(

"<a href=http://www.google.co.th><img src=mkv/iron1.jpg alt=iron1 border=0 width=109 height=162 rel=<h1> test1 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/gi.jpg alt=G.I.Joe border=0 width=109 height=162 rel=<h1> test2 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/tron.jpg alt=tron border=0 width=109 height=162 rel=<h1> test3 </a>",
"<a href=http://www.google.co.th><img src=mkv/pirates4.jpg alt=pirates4 border=0 width=109 height=162 rel=<h1> test4 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/wall.jpg alt=wall-e border=0 width=109 height=162 rel=<h1> test5 </a>",
"<a href=http://www.google.co.th><img src=mkv/green.jpg alt=green border=0 width=109 height=162 rel=<h1> test6 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/Priest.jpg alt=Priest border=0 width=109 height=162 rel=<h1> test7 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/thor.jpg alt=thor border=0 width=109 height=162 rel=<h1> test8 </a>",
"<a href=http://www.google.co.th><img src=mkv/transformers3.jpg alt=transformers3 border=0 width=109 height=162 rel=<h1> test9 </h1></a>",

);

echo $quotes[rand(0, count($quotes) - 1)];
$ran = $quotes[rand(0, count($quotes) - 1)];
}
function testtwo(){
$quotes = array(

"<a href=http://www.google.co.th><img src=mkv/iron1.jpg alt=iron1 border=0 width=109 height=162 rel=<h1> test1 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/gi.jpg alt=G.I.Joe border=0 width=109 height=162 rel=<h1> test2 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/tron.jpg alt=tron border=0 width=109 height=162 rel=<h1> test3 </a>",
"<a href=http://www.google.co.th><img src=mkv/pirates4.jpg alt=pirates4 border=0 width=109 height=162 rel=<h1> test4 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/wall.jpg alt=wall-e border=0 width=109 height=162 rel=<h1> test5 </a>",
"<a href=http://www.google.co.th><img src=mkv/green.jpg alt=green border=0 width=109 height=162 rel=<h1> test6 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/Priest.jpg alt=Priest border=0 width=109 height=162 rel=<h1> test7 </h1></a>",
"<a href=http://www.google.co.th><img src=mkv/thor.jpg alt=thor border=0 width=109 height=162 rel=<h1> test8 </a>",
"<a href=http://www.google.co.th><img src=mkv/transformers3.jpg alt=transformers3 border=0 width=109 height=162 rel=<h1> test9 </h1></a>",
);	

echo implode($quotes);
}
?>
ส่วนไฟล์ random.php เอาไว้ include จาก mkv.inc.php (เอาไว้ แรนด้อม ภาพ)
อันนี้คือ code ครับ

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="116" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td height="250" align="center" valign="top" bgcolor="#e9faed"><? include('mkv.inc.php'); testone(); ?></td>
  </tr>
</table>
</body>
</html>
ทุกอย่างก็ปกติดี แต่พอมาถึง อันนี้สิครับ ผมไปไม่เป็นเลยครับ - -*

ไฟล์ showall.php ซึ่งเอาไว้ โชว์รูปใน array ทั้งหมดนะครับ
อันนี้ code ครับ

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="116" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td height="250" align="center" valign="top" bgcolor="#e9faed"><? include('mkv.inc.php'); testtwo(); ?></td>
  </tr>
</table>
</body>
</html>
ซึ่ง ผลลัพธ์ ที่ได้ จะเป็น แบบนี้ครับ คือเรียงลงไปเรื่อยๆ
รูป2
รูป2
2.jpg (41.98 KiB) Viewed 7624 times
สิ่งที่ผมต้องการคืออยากให้มัน เป็นนี้นะครับ
รูป3
รูป3
3.jpg (129.84 KiB) Viewed 7624 times
อยากให้เรียงมาเป็น 4 คอลัมน์ในตาราง พอครบ 4 ก็ เพิ่ม rows ไปอีก เป็นแบบนี้ไปเรื่อยๆ นะครับ

คือผมต้องแก้ไฟล์ไหนบ้างอะครับ ทำมา 2 คืนแล้วยังไม่ได้เลย ครับ ขอบคุณที่ช่วยตอบนะครับ พึ่งโพส ครั้งแรก ผิดผลาดอย่างใด ขออภัยด้วยนะครับ

ข้างบน