ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: SG14 ที่ 21 สิงหาคม 2013, 16:34:35



หัวข้อ: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: SG14 ที่ 21 สิงหาคม 2013, 16:34:35
ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ

โดยรูปแบบที่ต้องการประมาณนี้อะค่ะ
(http://upic.me/i/05/13untitled-2.jpg)

โค๊ดที่ทำอยู่ มันไม่จัดแถวละ 4 บล๊อคอะค่ะ

โค๊ด:
 <table width="980" border="0" cellpadding="0" cellspacing="0" align="center">
          <tr>
  <?
include("connectdb.php");

$sql1 = "SELECT* from article ORDER BY id DESC";
$query1 = mysql_query($sql1);
while ($rs1 = mysql_fetch_array($query1)){
$id1=$rs1[id];
$thumnail1 =$rs1[thumnail];
$title1=$rs1[title];
$detail1=$rs1[detail];
?>

        <td>
        <!-- เริ่มบล๊อคที่ต้องการแสดง -->
         <table id="Table_02" width="235" height="280" border="0" cellpadding="0" cellspacing="0">
            <tr>
           
                <td background="images/infographic_level2_01.png" width="235" height="30"></td>
            </tr>
            <tr>
                <td background="images/infographic_level2_02.png" width="235" height="168" align="center" valign="middle">
                   <img src='administrator/<?php echo $thumnail1 ;?>' width="220" height="152"></td>
            </tr>
            <tr>
                <td background="images/infographic_level2_03.png" width='235' height='82' valign="top">
                 <div align="left"  style="padding-left:5px; padding-right:5px;" class="style2"><?php echo $title1 ;?></div>
                  <div align="right" style="padding-right:10px;"><img src="images/read1.jpg" border ="0"  /></div>
                             </td>
                        </tr>
                  </table>
       
        </td>
       <?  } ?>
      </tr>
</table>
รบกวนช่วยทีนะคะ

 :wanwan017: :wanwan017: :wanwan017:


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: smapan ที่ 21 สิงหาคม 2013, 16:39:07
แนะนำให้ใช้ CSS ครับ

เปลี่ยน Table เป็น Div ครับ


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: SG14 ที่ 21 สิงหาคม 2013, 16:47:18
แนะนำให้ใช้ CSS ครับ

เปลี่ยน Table เป็น Div ครับ

พอจะเขียนให้ดูได้ไหมค่ะ


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: seonew ที่ 21 สิงหาคม 2013, 16:51:28
ถ้าใช้ table คงต้อง เรียกมาทีล่ะแถวป่าวครับ  :P




หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: iLhay ที่ 21 สิงหาคม 2013, 16:53:14
ใช้ Bootstrap ทำ css แล้วใช้ span แบ่งเอาก็ได้ สบายๆ

http://getbootstrap.com/2.3.2/scaffolding.html#gridSystem


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: smapan ที่ 21 สิงหาคม 2013, 16:55:35
แนะนำให้ใช้ CSS ครับ

เปลี่ยน Table เป็น Div ครับ

พอจะเขียนให้ดูได้ไหมค่ะ
โค๊ด:
<? 
include("connectdb.php");
$count = 1;
$sql1 = "SELECT* from article ORDER BY id DESC";
$query1 = mysql_query($sql1);
while ($rs1 = mysql_fetch_array($query1)){
$id1=$rs1[id];
$thumnail1 =$rs1[thumnail];
$title1=$rs1[title];
$detail1=$rs1[detail];
$count ++;
?>
<div id="a<?=$count?>">
<div id="b<?=$count?>">
    <img src='administrator/<?=$thumnail1?>/>
</div>
<div id="c<?=$count?>">
    <?php echo $title1 ;?>
</div>
</div>
<?  } ?>


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: SG14 ที่ 22 สิงหาคม 2013, 10:39:28
แนะนำให้ใช้ CSS ครับ

เปลี่ยน Table เป็น Div ครับ

พอจะเขียนให้ดูได้ไหมค่ะ
โค๊ด:
<? 
include("connectdb.php");
$count = 1;
$sql1 = "SELECT* from article ORDER BY id DESC";
$query1 = mysql_query($sql1);
while ($rs1 = mysql_fetch_array($query1)){
$id1=$rs1[id];
$thumnail1 =$rs1[thumnail];
$title1=$rs1[title];
$detail1=$rs1[detail];
$count ++;
?>
<div id="a<?=$count?>">
<div id="b<?=$count?>">
    <img src='administrator/<?=$thumnail1?>/>
</div>
<div id="c<?=$count?>">
    <?php echo $title1 ;?>
</div>
</div>
<?  } ?>

มีวิธีไหนให้แสดง บรรทัดละ 4คอลัมแล้วตัดขึ้นใหม่บ้างค่ะ  :wanwan015: :wanwan017:


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: smapan ที่ 22 สิงหาคม 2013, 10:41:20
แนะนำให้ใช้ CSS ครับ

เปลี่ยน Table เป็น Div ครับ

พอจะเขียนให้ดูได้ไหมค่ะ
โค๊ด:
<? 
include("connectdb.php");
$count = 1;
$sql1 = "SELECT* from article ORDER BY id DESC";
$query1 = mysql_query($sql1);
while ($rs1 = mysql_fetch_array($query1)){
$id1=$rs1[id];
$thumnail1 =$rs1[thumnail];
$title1=$rs1[title];
$detail1=$rs1[detail];
$count ++;
?>
<div id="a<?=$count?>">
<div id="b<?=$count?>">
    <img src='administrator/<?=$thumnail1?>/>
</div>
<div id="c<?=$count?>">
    <?php echo $title1 ;?>
</div>
</div>
<?  } ?>

มีวิธีไหนให้แสดง บรรทัดละ 4คอลัมแล้วตัดขึ้นใหม่บ้างค่ะ  :wanwan015: :wanwan017:

โค้ดที่ให้ไปมันะเรียงบันทัดเดียว แล้วให้กำหนดรูปแบบจาก CSS  ครับ


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: sys2528 ที่ 22 สิงหาคม 2013, 11:34:41
ผมลองเขียนมาให้นะครับ จัดรูปแบบด้วย CSS ครับผม ใช้ ul  li เป็นตัวกำหนดการแสดงครับ

ลองดูครับ เอาไปปรับได้กับการ Query Database ครับ

โค๊ด:
<style type="text/css">
body{ margin:0px; padding:0px; font-size:14px;}
.colum{ width:600px; margin:auto; background-color:#CCCCCC;}
.colum ul{ margin:0px; padding:0px; list-style:none;}
.colum ul li{ float:left; margin:10px; width:120px; height:200px; line-height:100px; text-align:center; background-color:#FF9900; color:#FFFFFF;}
</style>
<div class="colum">
<ul>
<? for($i = 1; $i<=16; $i++){?>
<li><?=$i?></li>
<?  } ?>
</ul>
</div>


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: phpwin ที่ 22 สิงหาคม 2013, 13:24:39
ดึงข้อมูลออกมาแสดงเป็นคอลัมน์ใช่ไหมครับ ตามนี้ครับ
โค๊ด:
http://php-for-ecommerce.blogspot.com/2011/11/blog-post.html
เปลี่ยนคำสั่งตรง $setColumn=3; ให้เป็น $setColumn=4; เพื่อแสดง 4 คอลัมน์ต่อ1แถว
ที่เหลือก็ตกแต่งด้วย CSS เองนะครับ


หัวข้อ: Re: [PHP] ดึงข้อมูลออกมาจากดาต้าเบสแล้วอยากจัดรูปแบบ ค่ะ
เริ่มหัวข้อโดย: dragons_first ที่ 22 สิงหาคม 2013, 14:45:29
อันนี้แบบดั้งเดิม ใช้กันในหมู่ php

   $i=0;
   echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";
   forloop/whileloop(){
      $i++;
      echo "<td>";


      echo 'ใส่ดาต้าตรงนี้';

      if(($i)%4==0){//จำนวนที่จะให้แสดงต่อแถว
         echo "</tr>";
      }else{
         echo "</td>";
         }
   }
   echo "</table>";