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> Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/ 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517567 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517573 Share on other sites More sharing options...
craygo Posted April 15, 2008 Share Posted April 15, 2008 what is your code now?? Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517591 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517658 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517697 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517768 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517780 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517789 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517797 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517800 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 Link to comment https://forums.phpfreaks.com/topic/101181-solved-selecting-from-oracle-to-a-table-in-php/#findComment-517806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.