字段名称,使用PHP查询Oracle数据库 [英] Field names, querying Oracle database with PHP
本文介绍了字段名称,使用PHP查询Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面得到了此查询,以从数据库返回查询并在表中显示所有信息,然后由用户输入查询.
I have got this query below, to return a query from a database and display all of the information in a table, then query is user inputted.
有什么方法可以让字段名称填充到表格的顶部?否则,第一行是原始数据.我正在努力寻找一种方法来完成此工作,因此将不胜感激.
Is there any way to get the field names to populate at the top of the table? Otherwise the first row is the raw data. I am struggling to find a way to do this, so any help would be appreciated.
<?php
if ($safeparam1 === null) {
}
else {
$stid = oci_parse($conn, $safeparam1);
$r = oci_execute($stid);
print '<p><input type="button" value="Clear Results"
onclick=location.href=\'ul_move_query.php\';> <input type="submit"
value="Print Results">';
print '<table>';
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
print '<tr>';
foreach ($row as $item) {
print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) :
'').'</td>';
}
print '</tr>';
}
}
?>
推荐答案
在获取关联数组时,您可以简单地将数组键输出为标题行:
As you are fetching an associative array you can simply output the array keys as the header row:
$header = false; // a way to track if we've output the header.
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
if ($header == false) {
// this is the first iteration of the while loop so output the header.
print '<thead><tr>';
foreach (array_keys($row) as $key) {
print '<th>'.($key !== null ? htmlentities($key, ENT_QUOTES) :
'').'</th>';
}
print '</tr></thead>';
$header = true; // make sure we don't output the header again.
}
// output all the data rows.
print '<tr>';
foreach ($row as $item) {
print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) :
'').'</td>';
}
print '</tr>';
}
这篇关于字段名称,使用PHP查询Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文