eugene2009 Posted January 5, 2010 Share Posted January 5, 2010 Hello, im pretty sure this is simple but i just dont know how to. please help <?php // Make a MySQL Connection $query = "SELECT * FROM example"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['name']. " - ". $row['age']; ?> HOW do i make it that it would put 5 in one row and then break? for example: a b c d e f g h i j instead of a b c etc.. Link to comment https://forums.phpfreaks.com/topic/187207-fetching-rows/ Share on other sites More sharing options...
premiso Posted January 5, 2010 Share Posted January 5, 2010 You would want to look into the modulus (%) operator. Link to comment https://forums.phpfreaks.com/topic/187207-fetching-rows/#findComment-988596 Share on other sites More sharing options...
eugene2009 Posted January 5, 2010 Author Share Posted January 5, 2010 thats for c++ im pretty sure it can be done with php Link to comment https://forums.phpfreaks.com/topic/187207-fetching-rows/#findComment-988597 Share on other sites More sharing options...
premiso Posted January 5, 2010 Share Posted January 5, 2010 thats for c++ The math is still the same, it works for PHP using the %. So (1 % 2) would equal .5, give it a try: $num = (1%2); echo $num; It calculates if there is a remainder, if there is then you have not reached that number, if it is equaled to 0, you have reached your number and would want to insert a break. EDIT: And for the PHP reference of its usage: Arithmetic Operators. Link to comment https://forums.phpfreaks.com/topic/187207-fetching-rows/#findComment-988599 Share on other sites More sharing options...
PravinS Posted January 5, 2010 Share Posted January 5, 2010 Try this <?php $k = 1; while () // your while loop { // your code if ($k % 5 == 0) echo "<br>"; $k++; } ?> Link to comment https://forums.phpfreaks.com/topic/187207-fetching-rows/#findComment-988601 Share on other sites More sharing options...
eugene2009 Posted January 14, 2010 Author Share Posted January 14, 2010 awesome! it works! Link to comment https://forums.phpfreaks.com/topic/187207-fetching-rows/#findComment-994757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.