Jump to content

form button in loop


smeghead67

Recommended Posts

Hi, This is my first post here. I hope I can explain this so you fine people can help me.

 

On my web page im building at home, I have it getting data from the mysql server and it displays it with no problems. I added a form button at the end of each table row. that will, my goal, direct a person to the page that displays the item info.

for ($i=1;$i<=6;$i++)
{
  $row = mysql_fetch_array($result);
  extract($row);
  $f_price = number_format($msrp,2);
  $f_hb = number_format($high_bid,2);
  check_time_left($itemid);
  echo "<tr>\n
<td>$itemname</td>\n
        <td align='right'>\$$f_price</td>\n
        <td>$tlstring</td>\n
        <td align='right'>\$$f_hb</td>\n
        <td><form action='item.php' method='POST'>
        <input type='hidden' name='item_id' value='$itemid'>
        <input type='submit' value='view'></td>
        </tr>\n";
  echo "<tr><td colspan='5'><hr></td></tr>\n";
}
echo "</table>\n";

 

when i hit any button it always displays the info from the last item on my list? It does the same on another page with a while loop

 

any ideas?

 

Thank You

Smeghead67

Link to comment
Share on other sites

1) Please don't post PHP scripts in the HTML section. When you have an HTML question, the PHP is irrelevant. Post the output of your PHP script.

2) If you look at the HTML output of your script, it will probably quickly apparent to you why you are only seeing the value of the last item (hint: look at the 'name' attribute of two of the form elements from your loop).

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.