I'm trying to create a website in my scenario I need to retrieve many rows of data from my database. Each row displayed should have a button next to it with a unique name. The only problem is getting the button to have a unique name.
<?php
require_once 'php/login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "SELECT * FROM Bets_info WHERE BetGroup = '1'";
$result = $conn->query($query);
if(!result) die($conn->error);
$rows = $result->num_rows;
for ($j = 0; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_ASSOC);
echo '<button id="myBtn">Bet</button> ';
echo ' ' .$row['BetWin'] . '/';
echo ' ' .$row['BetLose'] . ' : ';
echo ' ' .$row['BetDescription'] . '<br><br>';
}
$result->close();
$conn->close();
?>
I have tried to do the following
for ($j = 0; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_ASSOC);
echo '<button id="myBtn<? $j ?>">Bet</button> ';
echo ' ' .$row['BetWin'] . '/';
echo ' ' .$row['BetLose'] . ' : ';
echo ' ' .$row['BetDescription'] . '<br><br>';
}
This does not make the buttons called
btn1, btn2, btn3
but instead it just calls all the buttons "myBtn<? $j ?>"
.