简体   繁体   English

在PHP中构造SQLite3查询

[英]Structure SQLite3 query in PHP

I'm quite new to PHP and SQLite. 我是PHP和SQLite的新手。

Is it possible to structure a SQLite3 query in PHP into a table? 是否可以将PHP中的SQLite3查询构建到表中?

I have the following code: 我有以下代码:

$result = $db->query('SELECT unique_id, description FROM dis_enums WHERE unique_id <= 12');
while ($row = $result->fetchArray()){
    print_r($row);
    echo nl2br("\n");
}

Which returns the following: 返回以下内容:

Array( [0] => 1 [unique_id] => 1 [1] => Concrete [description] => Concrete )

Array( [0] => 2 [unique_id] => 2 [1] => Bridge [description] => Bridge )

etc. 等等

Is there any way to change my code so it has headers (unique_id and description) with the results underneath? 有没有办法改变我的代码,所以它有标题(unique_id和描述)与下面的结果?

Thanks. 谢谢。

You can echo the headers before the content of your table. 您可以在表格内容之前回显标题。
If you want to construct a html-table that would look like that: 如果你想构建一个看起来像这样的html表:

$result = $db->query('SELECT unique_id, description FROM dis_enums WHERE unique_id <= 12');
echo "<table>";
echo "<tr>";
echo "<th>unique_id</th><th>description</th>";
echo "</tr>";
while ($row = $result->fetchArray()){
    echo '<tr>';
    echo '<td>' . $row['unique_id'] . '</td>';
    echo '<td>' . $row['description'] . '</td>';
    echo '</tr>';
}
echo "</table>";

There is a almost matching example here http://zetcode.com/db/sqlitephp/ 这里有一个几乎匹配的例子http://zetcode.com/db/sqlitephp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM