how to script the for loop in codeigniter using foreach |
[eluser]nOsCiRe[/eluser]
<?Php $num_data = $this->db->count_all('ad_users'); for ( $counter = 1; $counter <= $num_data; $counter += 1) { echo "<tr><td>"; echo $counter; echo "</td></tr>"; } echo "</table>"; ?>
[eluser]Akinzekeel[/eluser]
I don't think there's anything CI-specific about a foreach loop so I assume you'd like to know how to iterate through an active record resultset. This is how I usually do it: Controller (you probably already have something similar to that): Code: $this->db->select("something"); View: Code: <table> Note that I'm using alternative PHP syntax in the view (just for convenience). If you're new to it, have a look at http://ellislab.com/codeigniter/user-gui...e_php.html
[eluser]CroNiX[/eluser]
I believe count_all_results() returns a single integer telling how many rows a table has, not an array or any other data. Effectively, COUNT(*). So there's nothing to loop over in the first place. http://ellislab.com/codeigniter/user-gui...lpers.html
[eluser]Matalina[/eluser]
[quote author="CroNiX" date="1331742994"]I believe count_all_results() returns a single integer telling how many rows a table has, not an array or any other data. Effectively, COUNT(*). So there's nothing to loop over in the first place. http://ellislab.com/codeigniter/user-gui...lpers.html[/quote] he's not looping through the returned value he's using it as as top case in a for loop.
[eluser]skunkbad[/eluser]
For OP, here is your foreach documentation: http://php.net/manual/en/control-structures.foreach.php |
Welcome Guest, Not a member yet? Register Sign In |