Robert Martens
Robert Martens

Reputation: 173

repeating a button in a php while loop

The following is a markup I have for displaying my database:

$html = '';
$database_enquiry = tep_db_query("(relevant database enquiry in here)");
while ($database = tep_db_fetch_array($database_enquiry)){
    $html .= '<tr>';
    $html .= '      <td>'.$myV['myVariable goes here'].'</td>';
    $html .= '      <td><button id="editDriver"></button><button id="timeDriver"></button></td>';
    $html .= '</tr>';       
}

echo $html;

For some reason, the rows, are displaying in the loop, but the buttons are only showing up for the first row. Anyone know why?

Upvotes: 0

Views: 1464

Answers (3)

Timoth&#233;e Groleau
Timoth&#233;e Groleau

Reputation: 1950

IDs, as their name imply, should be unique to a document, you are duplicating the buttons IDs for every row.

Normaly most browsers don't make a fuss if you have dulicates (though they should), but it seems in your case, it's causing problems.

So, give your buttons unique IDs accross rows, or use classes to see if it helps:

$html .= '      <td><button class="editDriver"></button><button class="timeDriver"></button></td>';

Upvotes: 2

Vlad Preda
Vlad Preda

Reputation: 9910

There are 3 things you need to fix/check:

  • The id attribute id unique. You should not have more than one per page
  • <tr></tr> tags should be inside a <table></table> element.
  • Maybe your query return a single row, in which case your code is working properly.

Also, you should check the official documentation for the button element: http://www.w3.org/wiki/HTML/Elements/button

Upvotes: 0

IamFraz
IamFraz

Reputation: 136

Could you write something between the button tag and add type attribute?

<button type="button">Something</button>

ref

Upvotes: 0

Related Questions