 |
ถามหน่อยครับถ้าหากว่าผมต้องการให้ตัด "," ออกหลังจากที่วนลูปครับแล้วเช่น 00002,00004,00005, |
|
 |
|
|
 |
 |
|
$sql = "SELECT book_id FROM booking where status='1' or status='2' and check_in <= $checkout and check_out >= $checkin order by book_id asc";
$result=mysql_db_query($newDB,$sql);
$N = mysql_num_rows($result); //$N=นับจำนวนแถวที่ได้ตามเงื่อนไข $sql
$i = 1;
$tmpCODE="";
while ($row1=mysql_fetch_array($result)){
$book_id=$row1['book_id'];
$tmpCODE += $book_id;
$tmpCODE+= ",";
if($i==$N){
$tmpCODE+= "";
}
$i++;
}
ไม่รู้ตรงที่ต้องการเปล่า นะคัรบ ผม แค่ ลองเสนอแนวคิดครับ
|
 |
 |
 |
 |
Date :
2009-11-12 11:30:48 |
By :
exeman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<!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=windows-874" />
</head>
<body>
<?
$book_id = "00002,00004,00005";
$dd = explode(",", $book_id);
echo $dd[0].$dd[1].$dd[2];
//000020000400005
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2009-11-12 11:40:47 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$txt="00002,00004,00005,";
if(preg_match('/,$/',$txt)){ // ตรวจสอบตัวสุดท้ายเป็น ,
$txt= preg_replace('/,$/','',$txt); // ลบ , ตัวสุดท้ายออก
}
echo $txt;
?>
|
 |
 |
 |
 |
Date :
2009-11-12 12:50:30 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ทำได้แล้วไม่ใช่หรอครับก็ตัดตรง
echo $book_id. ",";
เป็น
echo $book_id;
เอาลูกน้ามออกเองอะ
|
 |
 |
 |
 |
Date :
2009-11-12 13:16:14 |
By :
hamzter |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$sql = "SELECT book_id FROM booking where status='1' or status='2' and check_in <= $checkout and check_out >= $checkin order by book_id asc";
echo $sql;
$result=mysql_db_query($newDB,$sql);
$N = mysql_num_rows($result); //$N=นับจำนวนแถวที่ได้ตามเงื่อนไข $sql
//echo"จำนวนแถวที่ได้ = $N";
while ($row1=mysql_fetch_array($result)){
$book_id=$row1['book_id'];
//echo $book_id. ",";
if(preg_match('/,$/',$book_id)){ // ตรวจสอบตัวสุดท้ายเป็น ,
$book_id= preg_replace('/,$/','',$book_id); // ลบ , ตัวสุดท้ายออก
}
echo $book_id;
}
ตัว , ก็หายหมดเลยอะครับพี่ 000020000400005 อยากให้มันเป็น 00002,00004,00005 อะครับ
|
 |
 |
 |
 |
Date :
2009-11-12 14:02:54 |
By :
giroo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อย่าทำในลูปสิครับ
Code
$sql = "SELECT book_id FROM booking where status='1' or status='2' and check_in <= $checkout and check_out >= $checkin order by book_id asc";
echo $sql;
$result=mysql_db_query($newDB,$sql);
$N = mysql_num_rows($result); //$N=นับจำนวนแถวที่ได้ตามเงื่อนไข $sql
//echo"จำนวนแถวที่ได้ = $N";
$book_id ="";
while ($row1=mysql_fetch_array($result)){
$book_id .=$row1['book_id'].",";
//echo $book_id. ",";
}
if(preg_match('/,$/',$book_id)){ // ตรวจสอบตัวสุดท้ายเป็น ,
$book_id= preg_replace('/,$/','',$book_id); // ลบ , ตัวสุดท้ายออก
}
echo $book_id;
|
 |
 |
 |
 |
Date :
2009-11-12 14:31:37 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ xbeginner01 มากนะครับ +1 ครับพี่
|
 |
 |
 |
 |
Date :
2009-11-12 14:58:23 |
By :
giroo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|