Convert SQL query / loop into PDO -


i trying pdo results displayed in table via loop. presently displaying white page. suggestions missing? or why page blank?

<?php  try {  $conn = new pdo("pgsql:host=localhost port=5432 dbname=riverflies_gis", "opengeo", "opengeo");  echo "pdo connection object created";  echo "<br>"; } catch(pdoexception $e) {   echo $e->getmessage(); }    $sql  = "select admin_name, adminuser_id, group_id adminuser_tbl";   $stmt = $conn->prepare($sql);   $stmt->execute();   $data = $stmt->fetchall(); ?>          <table border='1' cellpadding='10'>         <tr>         <th>id</th>         <th>adminuser</th>         <th>group_id</th>         <th></th>        </tr>  <?php foreach ($data $row): ?> <tr> <td><?=$row['adminuser_id']?></td> <td><?=$row['admin_name']?></td> <td><?=$row['group_id']?></td> </tr> <?php endforeach ?> </table> 

please never mix database operations html output.

pdo it. data first:

$sql  = "select admin_name, adminuser_id, group_id adminuser_tbl"; $stmt = $conn->prepare($sql); $stmt->execute(); $data = $stmt->fetchall(); 

and output in template:

<table border='1' cellpadding='10'>  <tr>   <th>id</th>   <th>first name</th>   <th>last name</th>   <th></th>   <th></th>  </tr> <? foreach ($data $row): ?>  <tr>   <td><?=$row['id']?></td>   <td><?=$row['firstname']?></td>   , on  </tr> <? endforeach ?> </table> 

see how nice , clean output code can be


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -