我有一个包含以下字段的数据库:
eventname(事件的名称 - 文本) datestart(事件的开始日期 - 例如../../ ..) dateend(事件的结束日期 - 例如../../ ..)我需要创建一个包含3列的表,但是需要多行,具体取决于有多少事件。
下面是我正在使用的代码,用于将数据库数据存储在数组中:
$allevents = mysql_query("SELECT * FROM Events ORDER BY datestart ASC"); while($event = mysql_fetch_array($allevents)){正如我所说,然后我需要在表格中显示数据。
我真的很感激如何实现这一点,因为我对PHP很新。
I have a database with the following fields:
eventname (the name of the event - text) datestart (the start date of the event - e.g. ../../..) dateend (the end date of the event - e.g. ../../..)I need to create a table with 3 columns, and however many rows depending on how many events there are.
Here is the code I'm using at them moment to store the database data in an array:
$allevents = mysql_query("SELECT * FROM Events ORDER BY datestart ASC"); while($event = mysql_fetch_array($allevents)){As I said, I then need to to display the data in a table.
I'd really appreciate some help as to how to achieve this, as I'm very new to PHP.
最满意答案
您是否熟悉Alex Garret在TheNewBoston或(他自己的网站)phpAcademy.org上的免费十分钟教程?
这些可能对你有很大帮助:
TheNewBoston.com上有200个PHP视频
phpAcademy.org上的PHP教程
基本上:
$allevents = mysql_query("SELECT * FROM Events ORDER BY datestart ASC"); $out = '<table><tr><td>Name</td><td>Address</td></tr>'; while($event = mysql_fetch_array($allevents)){ $name = $event['name']; $addr = $event['addr']; $out .= '<tr>'; $out .= '<td>' .$name. '</td>'; $out .= '<td>' .$addr. '</td>'; $out .= '</tr>'; } $out .= '</table>'; echo $out;Are you familiar with Alex Garret's FREE ten-minute tutorials on TheNewBoston or (his own site) phpAcademy.org?
These may help you greatly:
200 PHP videos at TheNewBoston.com
PHP tutorials at phpAcademy.org
Basically:
$allevents = mysql_query("SELECT * FROM Events ORDER BY datestart ASC"); $out = '<table><tr><td>Name</td><td>Address</td></tr>'; while($event = mysql_fetch_array($allevents)){ $name = $event['name']; $addr = $event['addr']; $out .= '<tr>'; $out .= '<td>' .$name. '</td>'; $out .= '<td>' .$addr. '</td>'; $out .= '</tr>'; } $out .= '</table>'; echo $out;更多推荐
发布评论