怎么实现PHP调用MYSQL数据库,实现数据横排?

怎么实现PHP调用MYSQL数据库,实现数据横排?,第1张

你不要加那些DIV、UL、LI呀,只要有它们,肯定是竖排,比如下面这样:

while($row=mysql_fetch_row($result))

{

echo "<a href='$row[2]' target='_blank'>$row[1]</a>"

}

或者使用TABLE,语句是:

echo '<table><tr>'

while($row=mysql_fetch_row($result))

{

echo "<td><a href='$row[2]' target='_blank'>$row[1]</a>"

}

echo '</table>'

1、在mysql环境,创建数据表,

create table test_data1(id int, name VARCHAR(20), day VARCHAR(20))

2、插入测试数据

insert into test_data1 values(1,'liu',1)

insert into test_data1 values(2,'liu',3)

insert into test_data1 values(3,'wang',1)

insert into test_data1 values(4,'wang',2)

insert into test_data1 values(4,'wang',4)

3、查询表中数据,select * from test_data1;

4、编写目标sql;

select name, 

     max(case when day=1 then 1 end) d_1,

     max(case when day=2 then 2 end) d_2,

     max(case when day=3 then 3 end) d_3,

     max(case when day=4 then 4 end) d_4

from test_data1 t group by name


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7312000.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存