xiimoss xiimoss - 5 months ago 27
PHP Question

Dynamic href when generating buttons?

I have a table that is displaying data to the user and each row in the table has a unique id, in the table I am generating a button for each row to get more information on the content in the row. However, i need to generate a unique href for each button based on the Unique ID of the data in the row. The way I have done it it correctly goes to the link in the href but without passing the Unique ID.

<?php while($row = $query->fetch()) { ?>
<td><?php echo $row['car_id']; ?></td>
<td><?php echo $row['car_make']; ?></td>
<td><?php echo $row['car_model']; ?></td>
<td><?php echo $row['number_available']; ?></td>
<td><?php echo $row['rent_cost_per_day']; ?></td>

<td><a class="btn btn-default" href="cars.php?"<?php $row['car_id']; ?>>View</a></td>

<?php } ?>

Any help?


This is because you put the php after you closed the href quotes. You also have not put an echo function for the php, and have not put a get variable. You have:

href="cars.php?"<?php $row['car_id']; ?>

What you want to have is:

href="cars.php?id=<? echo $row['car_id']; ?>"