DYNAMIC TABLE - BUTTON IN EACH ROW

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keopz
Forum Newbie
Posts: 2
Joined: Wed May 27, 2009 3:35 pm

DYNAMIC TABLE - BUTTON IN EACH ROW

Post by keopz »

Hello,

I have a table created with a While statement that posts rows from a SQL table. One of the cells has an ID

So, I want to put a button in each row that redirects the user to a generic page where the ID value is posted and can be used to display further information.

Page 1:

Code: Select all

 
while($row = mysql_fetch_array($list, MYSQL_ASSOC))
{    
echo "
  <tr>
    <td>{$row['ID']}</td>
    <td>{$row['value2']}</td>
    <td>{$row['valueN']}</td>
    <td> "where I want the button" </td>
  </tr>
";}
 
Page 2:

Code: Select all

 
<? echo "choosed ID"; ?>
Ideas?
Last edited by Benjamin on Fri May 29, 2009 10:14 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: DYNAMIC TABLE - BUTTON IN EACH ROW

Post by pickle »

Wrap the whole table in a form that posts to the second page. In each row, give each button the same name, but a different value - the value being the ID of the row. When the button is clicked, the value of the button will tell you which button was clicked.

Say, for example, you set the name of the button to "chosen_row", and give it a value of $row['ID'] (which we'll say is 1,2,3,4, etc). When the button is clicked for row 4, and the form is submitted, then $_POST['chosen_row'] will contain the value "4".

Also, please wrap your PHP code in tags so we get proper spacing & syntax highlighting.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply