Jump to content

First time working with PHP - While into For loop - Working with a result set.


Recommended Posts

I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop.  The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information.  Any help would be appreciated. 


while ($row = mysql_fetch_assoc($data_result_set)) {

echo "<td>".$row["product_id"]."</td>";

echo "<td>".$row["city"]."</td>";

echo "<td>".$row["quantity"]."</td>";




*** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable.




for($i = 0; $i <= $count; $i++){

echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>";

echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>";

echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>";




I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out.


Any help would be appreciated.

Thanks in advance.

Link to comment
Share on other sites


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.