I'm trying to dynamically return rows from the database with the variable from each row being associated with a numerically named variable. I have been able to code like the following but is there a way to do this with For Each or something similar?
$sql1 = "SELECT rate, date FROM MyTable WHERE number='1'";
$result1 = mysqli_query($con,$sql1) or die ("Query error: " . mysqli_error());
while($row1 = mysqli_fetch_assoc($result1)) {
$rate1=$row1['rate'];
$date1=$row1['date'];
}
$sql2 = "SELECT rate, date FROM MyTable WHERE number='2'";
$result2 = mysqli_query($con,$sql2) or die ("Query error: " . mysqli_error());
while($row2 = mysqli_fetch_assoc($result2)) {
$rate2=$row2['rate'];
$date2=$row2['date'];
}
Ie like the following:
$sqlALL = "SELECT rate, date FROM MyTable";