dougudu3564 2013-10-20 18:46
浏览 29

PostgreSQL数据库中的第一条记录不被PHP代码读取

I have a PostgreSQL database with some information about projects contained with in it. So each project has a name, description and contact but I'm looking to just pull the name attribute from the table using PHP.

I currently have two projects in my database.

ID | Name |
1  | Fruit project |
2  | Vegetable project |

And I have a PHP script below which generates

$res = pg_query("SELECT * FROM projects");
$assoc = pg_fetch_assoc($res);
$result = $assoc['name'];

/* FETCHES THE RESULT OF THE SQL QUERY WHICH GETS THE NAME OF EACH PROJECT */
while($row = pg_fetch_assoc($res))
{
    $output[]=$row['name'];
    print (json_encode($output));
}  /* CONVERTED ON MOBILE PLATFORM */

But the output of that file is current 'Vegatable project'. Could any provide some help on why the script isn't producing the first result as well?

  • 写回答

2条回答 默认 最新

  • douzhaiyuan1731 2013-10-20 18:48
    关注

    Because you're stripping it out off the result before your loop:

    $res = pg_query("SELECT * FROM projects");
    $assoc = pg_fetch_assoc($res); // <-- remove
    $result = $assoc['name'];      // <-- remove
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了