Jump to content

[SOLVED] selecting from oracle to a table in php


bundred

Recommended Posts

iv got a problem, im trying to select all from a table i have in oracle. i can do this but the table it gets outputted to is not working correctly.

 

http://ivy.shu.ac.uk/~rbundred/assignment/select_all_from_accomnew.php

 

here is the problem and the code is below.

 

 

$query="select * from Accommodation";

$stmt=ociparse($conn,$query);

ociexecute($stmt);

$nofields=ocinumcols($stmt);

 

print "<table border=1>";

while(ocifetchinto($stmt,$row))

{

 

for($i=1;$i<=$nofields;$i++)

{

   print "<th>".ocicolumnname($stmt,$i)."</th>";

   }

 

print "<tr>";

 

 

   

   $i=0;

   while($i<$nofields)

   {

      print "<td>".$row[$i]."</td>";

      $i++;

   }

   

}

 

?>

</body></html>

You have your data results inside the same loop as the field names. You only want the field names to run once so put your field names and data results inseperate loops.

 

<?php
$query="select * from Accommodation";
$stmt=ociparse($conn,$query);
ociexecute($stmt);
$nofields=ocinumcols($stmt);

print "<table border=1>";
while(ocifetchinto($stmt,$row))
{
  for($i=1;$i<=$nofields;$i++)
  {
  print "<th>".ocicolumnname($stmt,$i)."</th>";
  }
print "<tr>";
}
$i=0;
while($i<$nofields)
{
print "<td>".$row[$i]."</td>";
$i++;
}
?>

 

Ray

OK try this

 

<?php
$query="select * from Accommodation";
$stmt=ociparse($conn,$query);
ociexecute($stmt, OCI_DEFAULT);
$nofields=ocinumcols($stmt);

print "<table border=1>";
for($i=1;$i<=$nofields;$i++)
{
print "<th>".ocicolumnname($stmt,$i)."</th>";
}
$i=0;
$n=0;
while($row = oci_fetch_array($stmt, OCI_NUM))
{
echo "<tr>\n";
  while($i < $nofields){
  echo "<td>".$row[$i]."</td>";
  $i++;
  }
$n++;
$i=0;
echo "</tr>";
}
?>

 

Ray

 

 

damn I'm using php5. oci_fetch_array started in php 5.

 

Well change this

while($row = oci_fetch_array($stmt, OCI_NUM))

 

to this

while(ocifetchinto($stmt, $row, OCI_NUM))

 

I have an oracle database here and it works on this one.

 

Let me know

 

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.