spfoonnewb Posted January 27, 2007 Share Posted January 27, 2007 I'm a complete noob with foreach.. and I tested forever, and could only get it to work with mysql, is there a way to do this with foreach, or a for statement? I always got errors. I basically put a couple thousand empty rows in the database (To display form fields), it's not slow or anything.. just lame in my opinion..[code]<?php//Start While Loopif (isset($_POST["rows"])) { $link = mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $rows= mysql_query("SELECT * FROM `test` LIMIT ".$_POST["rows"].""); while($row = mysql_fetch_array( $rows )) { echo ''.$row['id'].'';} }//End While Loop?>[/code] Link to comment https://forums.phpfreaks.com/topic/35922-solved-replace-while-loop-with-for-loop/ Share on other sites More sharing options...
trq Posted January 27, 2007 Share Posted January 27, 2007 In this case your actually better off using a while() thats what they are for. Link to comment https://forums.phpfreaks.com/topic/35922-solved-replace-while-loop-with-for-loop/#findComment-170366 Share on other sites More sharing options...
spfoonnewb Posted January 27, 2007 Author Share Posted January 27, 2007 I just wanted to eliminate the mysql, but when I looked up the while loop I realized you don't have to use mysql to use it...[code]while ($show++ <= $_POST["rows"] - 1) [/code] Link to comment https://forums.phpfreaks.com/topic/35922-solved-replace-while-loop-with-for-loop/#findComment-170374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.