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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.