Page 1 of 1

DYNAMIC TABLE - BUTTON IN EACH ROW

Posted: Wed May 27, 2009 3:45 pm
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?

Re: DYNAMIC TABLE - BUTTON IN EACH ROW

Posted: Wed May 27, 2009 5:14 pm
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.