ยินดีต้อนรับ กรุณา สมัครสมาชิก หรือเข้าสู่ระบบ

Home » webboard » PHP
เข้าชม : 626

ดึงฐานข้อมูลเป็น 2 คอลัม และใช้ฟังก์ชั่นตัดคำด้วย

โพสต์เมื่อ: วันอาทิตย์ 29 พฤษภาคม 2554  17:56 น.

<div align="center">
   <?

function utf8_substr($str,$start_p,$len_p)
{
   preg_match_all("/./u", $str, $ar);

   if(func_num_args() >= 3) {
       $end = func_get_arg(2);
       return join("",array_slice($ar[0],$start_p,$len_p));
   } else {
       return join("",array_slice($ar[0],$start_p));
   }
}
// การใช้งาน
// $start_p คือตำแหน่งเริ่มต้นตัดข้อความ
// $len_p คือจำนวนตัวอักษรที่ต้องการแสดง
// $data="ข้อความทดสอบ ข้อความทดสอบ ข้อความทดสอบ ข้อความทดสอบข้อความทดสอบ ";
// echo utf8_substr($data,0,30);

  
 include "connect.php";
 $sql = "SELECT * from tb_question where c_food ='yes' order by id_ques DESC";
 $result = mysql_query($sql);
 echo"<table border=\"0\"  cellspacing=\"1\" cellpadding=\"1\"><tr>"; 
 $count = 0;
 while($arr= mysql_fetch_array($result))
 {
 $id_ques=$arr["id_ques"];
 $photo_ques=$arr["photo_ques"];
 $title_ques=$arr["title_ques"];
 $title_ques=utf8_substr($title_ques,0,33);

 $count++;
 echo "<td>";         
 ?>
   <table width="100" border="0" cellspacing="2" cellpadding="2">
        <tr>
          <td valign="top"><div align="left"><a href="answer_view.php?id_ques=<?=$id_ques?>" target="_blank"><img src="photo/<?=$photo_ques;?>" width="100" height="100" border="0"></a></div></td>
        </tr>
        <tr>
          <td valign="top"><div align="left"><?=$title_ques;?></div></td>
        </tr>
      </table>
     <?
  echo"</td>";
  if(($count)%2==0)
  {
  echo"</tr>";
  }
  else
  {
  echo "<td>";
  } 
 }
 echo"</tr></table>";
 ?>
     <?
 mysql_close();
 ?> 
 
  </div>


ฟังก์ชั่นตัดคำ


คุณต้องสมัครสมาชิก ถึงจะโพสกระทู้ได้

ปิดรับสมัครสมาชิกแล้ว


คำยอดฮิต :- 0