BEGIN
DECLARE userNames varchar(500) DEFAULT ''; ##用戶名字
DECLARE sums int DEFAULT 0;
DECLARE namess varchar(500) DEFAULT '';
DECLARE i int;
set i = 0;
select count(*) into sums from book where price = 123;
##select name into namess from book where price = 123;##這個是錯誤的因為這條sql 返回的有多條數據
while i < sums
DO
set i = i+1;
end while;
END
上述select 中 結果為:
id name price
1 aa 123
2 bb 123
我想把得到的多條數據中 name字段裡的值拿出來拼成 aa,bb 這樣的字符傳 怎麼做,請大家幫幫我.感激不盡
$name = '';
$sql = "select name from book where price=123";
$que = mysql_query($sql) or die(mysql_error());
while($arr = mysql_fetch_assoc($que)){
$name .=','.$arr['name'];
}
echo substr($name,1);