Jump to content

[SOLVED] Replace while loop, with for loop


spfoonnewb

Recommended Posts

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 Loop

if (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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.