bundred Posted April 15, 2008 Share Posted April 15, 2008 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> Quote Link to comment Share on other sites More sharing options...
craygo Posted April 15, 2008 Share Posted April 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
bundred Posted April 15, 2008 Author Share Posted April 15, 2008 hi thanks for the help but this doesnt work either result shown below http://ivy.shu.ac.uk/~rbundred/assignment/php_freak.php Quote Link to comment Share on other sites More sharing options...
craygo Posted April 15, 2008 Share Posted April 15, 2008 what is your code now?? Quote Link to comment Share on other sites More sharing options...
bundred Posted April 15, 2008 Author Share Posted April 15, 2008 the code at the minute is what you gave me Rob Quote Link to comment Share on other sites More sharing options...
craygo Posted April 15, 2008 Share Posted April 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
bundred Posted April 15, 2008 Author Share Posted April 15, 2008 nope this gives an error result is http://ivy.shu.ac.uk/~rbundred/assignment/select_all_from_accomtest.php Rob Quote Link to comment Share on other sites More sharing options...
craygo Posted April 15, 2008 Share Posted April 15, 2008 What version of php are you running Ray Quote Link to comment Share on other sites More sharing options...
bundred Posted April 15, 2008 Author Share Posted April 15, 2008 4.4.8 its the university server im running on Quote Link to comment Share on other sites More sharing options...
craygo Posted April 15, 2008 Share Posted April 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
bundred Posted April 15, 2008 Author Share Posted April 15, 2008 yes this works now! thanks for all your help. Rob Quote Link to comment Share on other sites More sharing options...
craygo Posted April 15, 2008 Share Posted April 15, 2008 Anytime. Don't forget to mark the thread as solved. Ray Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.