Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
PHP echo rows in table
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="oxuwazet" data-source="post: 453112" data-attributes="member: 88455"><p>Kinda hard to spot errors with improper code indentation and missing start tags.</p><p></p><p>From looking at it is because you put that code in a while loop. So its looping that code so 19 results times how ever times the while loop goes. To clear it up is some rows show up as 7 is because with 19 results it leaves one on a row by its self then returns the whole loop and the loop shows 6 more results so ultimately showing 7.</p><p></p><p>Here is how you should implement it.</p><p></p><p>[PHP]<?php</p><p></p><p>// your code here.</p><p></p><p>// the number of results.</p><p>$noof = sqlsrv_num_rows($stmt);</p><p></p><p>// the number of results in a row.</p><p>$ross = 6;</p><p></p><p>// start tables logic.</p><p></p><p>echo "<tr>\n";</p><p>$i = 0;</p><p>while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {</p><p> $i++;</p><p> if ($i % $ross == 0) {</p><p> output_row_data($row);</p><p> echo "</tr>\n";</p><p> if (!($noof - 1 < $i)) {</p><p> echo "<tr>\n";</p><p> }</p><p> } else {</p><p> output_row_data($row);</p><p> }</p><p>}</p><p>if (!($i % $ross == 0)) {</p><p> echo "</tr>\n";</p><p>}</p><p></p><p>// end tables logic.</p><p></p><p>// make the output row data function.</p><p></p><p>function output_row_data(array $row)</p><p>{</p><p> // out your row data.</p><p>}</p><p></p><p>?>[/PHP]</p></blockquote><p></p>
[QUOTE="oxuwazet, post: 453112, member: 88455"] Kinda hard to spot errors with improper code indentation and missing start tags. From looking at it is because you put that code in a while loop. So its looping that code so 19 results times how ever times the while loop goes. To clear it up is some rows show up as 7 is because with 19 results it leaves one on a row by its self then returns the whole loop and the loop shows 6 more results so ultimately showing 7. Here is how you should implement it. [PHP]<?php // your code here. // the number of results. $noof = sqlsrv_num_rows($stmt); // the number of results in a row. $ross = 6; // start tables logic. echo "<tr>\n"; $i = 0; while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $i++; if ($i % $ross == 0) { output_row_data($row); echo "</tr>\n"; if (!($noof - 1 < $i)) { echo "<tr>\n"; } } else { output_row_data($row); } } if (!($i % $ross == 0)) { echo "</tr>\n"; } // end tables logic. // make the output row data function. function output_row_data(array $row) { // out your row data. } ?>[/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
PHP echo rows in table
Top