cparekh Posted April 15, 2008 Share Posted April 15, 2008 Hi, I'm trying to output a table of results from a database query and I'm having trouble generating each row of results. There are 3 columns of values and I don't quite know how to get to each value to print it out. I'm testing $search_results->NumRows to make sure there is a result-set I've made a start with... for($i=0; $i < $search_results->NumRows; $i++) { while ($row = $search_results->Rows[$i]) { $p = $search_results; $Company = $p['Company']; $Contact = $p['Contact']; $Job = $p['Jobtitle']; print "<tr><td>$Company</td><td>$Contact</td><td>$Job</td></tr>"; } } however this caused my browser to hang so I'm guessing it goes into an infinite loop? How can I get to each row to print out? Any help is greatly appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/101202-array-trouble-with-outputting-a-table-of-results-from-a-db-query/ Share on other sites More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 Try this: <?php for($i=0; $i < $search_results->NumRows; $i++) { $row = $search_results->Rows[$i]; $Company = $row['Company']; $Contact = $row['Contact']; $Job = $row['Jobtitle']; print "<tr><td>$Company</td><td>$Contact</td><td>$Job</td></tr>"; } ?> Link to comment https://forums.phpfreaks.com/topic/101202-array-trouble-with-outputting-a-table-of-results-from-a-db-query/#findComment-517698 Share on other sites More sharing options...
cparekh Posted April 16, 2008 Author Share Posted April 16, 2008 Hi Aaron, Spot on - thanks very much! Looks like I got my looping all mixed up! Much appreciated. Link to comment https://forums.phpfreaks.com/topic/101202-array-trouble-with-outputting-a-table-of-results-from-a-db-query/#findComment-518265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.