使用php从数据库创建和更新表(Create and Update a table from database using php)

编程入门 行业动态 更新时间:2024-10-22 17:31:20
使用php从数据库创建和更新表(Create and Update a table from database using php)

我有一个包含以下字段的数据库:

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;

更多推荐

本文发布于:2023-07-23 00:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225191.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Create   php   database   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!