last_trace Posted December 21, 2006 Share Posted December 21, 2006 I want to display values from my database, I can call and display the information but..I need to display 5 values per row and then have it start a new line, etc.Foreach/For loop maybe? Not to comfortable with them. Link to comment https://forums.phpfreaks.com/topic/31534-showing-5-results/ Share on other sites More sharing options...
JP128 Posted December 21, 2006 Share Posted December 21, 2006 you can use a nested loop...but I am not very sure how to do it with PHP... lol, In my school's java class I can.. but they have stuff to do that.. I would actually like to know how to do this as well. Link to comment https://forums.phpfreaks.com/topic/31534-showing-5-results/#findComment-146107 Share on other sites More sharing options...
JP128 Posted December 21, 2006 Share Posted December 21, 2006 [url=http://www.php-mysql-tutorial.com/examples/source/paging/paging3.phps]http://www.php-mysql-tutorial.com/examples/source/paging/paging3.phps[/url]You can look there at a sample script...and here for the tutorial...[url=http://www.php-mysql-tutorial.com/php-mysql-paging.php]http://www.php-mysql-tutorial.com/php-mysql-paging.php[/url] Link to comment https://forums.phpfreaks.com/topic/31534-showing-5-results/#findComment-146110 Share on other sites More sharing options...
last_trace Posted December 21, 2006 Author Share Posted December 21, 2006 Actually i didn't want a paginationi wantex":result 1 | result 2 | result 3 | result 4 | result 5(<br />)result 6 | result 7 | result 8 | result 9 | result 10(<br />) Link to comment https://forums.phpfreaks.com/topic/31534-showing-5-results/#findComment-146112 Share on other sites More sharing options...
JP128 Posted December 21, 2006 Share Posted December 21, 2006 oh ... i see.Here is what I came up with.[code]<?php//Connect to the Database$i = 1;$sql = mysql_query ("SELECT column_name FROM `table_name`");while($row = mysql_fetch_assoc($sql)){echo $row['column'] . " | ";if($i == 5){echo "<BR>";$i = 0;}$i = $i + 1;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31534-showing-5-results/#findComment-146117 Share on other sites More sharing options...
The Little Guy Posted December 21, 2006 Share Posted December 21, 2006 Something like this could work:[CODE]<?php$number_rows = 1000; #You may need to change this. Chance to your liking.$number_columns = 5; #same with this. Chance to your liking.for($r=1;$r<$number_rows;$r++){ echo'<tr>'; for($c=1;$c<$number_columns;c++){ $row = mysql_fetch_array($row); if(!$row){ break; } echo'<td>'.$row['field_name'].'</td>'; } echo'</tr>';}?>[/CODE] Link to comment https://forums.phpfreaks.com/topic/31534-showing-5-results/#findComment-146120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.