Jump to content

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


nooberific

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.

 

$count=mysql_num_rows($data_result_set);

 

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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.