I have a database with structure
TableName | Row1 | Row2 | Row3 ...etc
My ‘Row’ table column goes up quite high, I wanted to try to query the database and use a variable in the row name to return my value, except it keeps returning NULL values, probably because it isn’t actually returning anything
<?php
$connection = mysqli_connect(....);
$sql = "SELECT * FROM table";
$result = $connection->query($sql);
if($result) {
while($row = $result->fetch_object()) {
for($i = 1; $i < 5; $i++) {
echo $row->Row.$i;
}
}
}
?>
I thought this would be the code but it doesnt work like this, currently I have the code set to
for(...
$myrow = 'Row'.$i;
echo $row->$myrow;
}
Which works although its a little sloppy and I assume there is a much nicer way of doing it
Perhaps this is what you mean:
Not sure if I understood the question correctly, though,