Php HTML表未显示PostgreSQL的第一条记录

Php HTML表未显示PostgreSQL的第一条记录,php,html,postgresql,Php,Html,Postgresql,我成功地用PostgreSQL的用户查询填充HTML表,但问题是,当我直接在PostgreSQL数据库上进行查询时,它会根据查询显示完整的记录,但当我在PHP中进行查询并用它填充HTML时,它不会显示第一条记录 例如,我有500条记录,我希望它们按DESC顺序排列 它应该表明: 500 499 498 ... 但它表明: 499 498 497 ... 因此,每次我打电话询问时,它总是“跳跃”第一条记录 可能是什么?显然我需要所有的记录 下面是我用来运行查询的代码($sql1),而$cone

我成功地用PostgreSQL的用户查询填充HTML表,但问题是,当我直接在PostgreSQL数据库上进行查询时,它会根据查询显示完整的记录,但当我在PHP中进行查询并用它填充HTML时,它不会显示第一条记录

例如,我有500条记录,我希望它们按
DESC
顺序排列 它应该表明:

500
499
498
...
但它表明:

499
498
497
...
因此,每次我打电话询问时,它总是“跳跃”第一条记录 可能是什么?显然我需要所有的记录

下面是我用来运行查询的代码($sql1),而$conexion是到我的postgresql数据库的连接:

$rs  =odbc_exec($conexion, $sql1);
$nr  =odbc_result($rs, 1);
if(!empty($nr)){
    print "
        <table width='992' border='1' class='Gtable'>
        <tr>
        <td width='46' bgcolor='#EEEDE8'><strong>Codigo<strong</td>
        <td width='46' bgcolor='#EEEDE8'><strong>Matricula</strong></td>
        <td width='100' bgcolor='#EEEDE8'><strong>Municipio</strong></td>
        <td width='150' bgcolor='#EEEDE8'><strong>Barrio</strong></td>
        <td width='80' bgcolor='#EEEDE8'><strong>Concepto</strong></td>
        <td width='50' bgcolor='#EEEDE8'><strong>Tipo Susp.</strong></td>
        <td width='200' bgcolor='#EEEDE8'><strong>Observacion</strong></td>
        <td width='156' bgcolor='#EEEDE8'><strong>Cliente</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Direccion</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Telefono</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>F.Grabacion</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Planificacion</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Inicio</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Finalizacion</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Efectiva</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Descripcion de Cierre</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Contratista</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Empleado</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>F.Cierre</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Genero</strong></td>
        <td width='151' bgcolor='#EEEDE8'><strong>Cerro</strong></td>
        </tr>";

        while($result =odbc_fetch_array($rs)){
                print "<tr>
                    <td align='left' valign='top'>".$result['cod_otrb']."</td>
                    <td align='left' valign='top'>".$result['cod_pred']."</td>
                    <td align='left' valign='top'>".$result['descripcion']."</td>
                    <td align='left' valign='top'>".$result['brdesc']."</td>
                    <td align='left' valign='top'>".$result['tqdesc']."</td>
                    <td align='left' valign='top'>".$result['cod_ttrb']."</td>
                    <td align='left' valign='top'>".$result['spdesc']."</td>
                    <td align='left' valign='top'>".$result['prnombre']."</td>
                    <td align='left' valign='top'>".$result['direccion']."</td>
                    <td align='left' valign='top'>".$result['telefono']."</td>
                    <td align='left' valign='top'>".$result['fecha_grab']."</td>
                    <td align='left' valign='top'>".$result['fecha_pla']."</td>
                    <td align='left' valign='top'>".$result['fecha_ini_trb']."</td>
                    <td align='left' valign='top'>".$result['fecha_pre_cierre']."</td>
                    <td align='left' valign='top'>".$result['efectiva']."</td>
                    <td align='left' valign='top'>".$result['otdesc']."</td>
                    <td align='left' valign='top'>".$result['ctnombre']."</td>
                    <td align='left' valign='top'>".$result['emnombre']."</td>
                    <td align='left' valign='top'>".$result['fecha_cierre']."</td>
                    <td align='left' valign='top'>".$result['usr_genera']."</td>
                    <td align='left' valign='top'>".$result['usr_cierra']."</td>
                    ";

        }
        print"</table>";
}else{
    print "<font color='#CC3333'><strong>No Hay Registros</strong></font>";
}
$rs=odbc\u exec($conexion,$sql1);
$nr=odbc_结果($rs,1);
如果(!空($nr)){
“打印”
Codigo您的问题(正如@Sean在评论中指出的)是这一行:

$nr =odbc_result($rs, 1);
正在从结果集中读取第一行,而您没有从该行输出数据。要解决此问题,我建议使用
if…do…while
结构:

if ($result = odbc_fetch_array($rs)) {
    // output the table headers here
    do {
        // output the row data
    } while ($result = odbc_fetch_array($rs));
}
else {
    // no data to output
}

记录索引是基于零的吗(从零开始)?如果是这样,你会得到0-499(500条记录)。虽然我不熟悉PostgreSQL/
odbc.*
,但我猜,
$nr=odbc.\U结果($rs,1);
正在提取第一条记录(500条),并将内部指针移动到下一条。因此,当您尝试循环结果时,它位于第二条记录处。您可能希望将该行更改为使用instead@Seanodbc_num_rows()不保证在
SELECT
查询中返回可用结果。