I'm working on a periodic table, in which I retrieve all the elements from my database. I want to place the elements in their respective position in the periodic table.
E.g.: Hydrogen is in row 1, cell 1 - Helium is in row 1, cell 18. The cells between those two should therefore be blank.
The problem is, that when I run my for-loop and compare the position - which is stored in my database - and the ID I've given each cell (which is the same as the position-outcome from the database), it only parses the first element and then stops.
It returns the first one 1-1 (Helium - Row 1, cell 1) and parses it like it should. Then the next one, which would be 1-2 (Row 1, cell 2), and from here on it just stops.
This is my query
// SQL Query for retrieving elements
$query = "
SELECT
id, name, symbol, row, cell
FROM
elements
ORDER BY
id
";
$objResult = $objConnection->query($query);
while ($row = $objResult->fetch_assoc()) {
// Creating two-dimensional, associative array containing each element
$ele[] = array(
'id' => $row['id'],
'name' => $row['name'],
'symbol' => $row['symbol'],
'position' => $row['row'].'-'.$row['cell']
);
}
And my for-loops
// Element counter
$cnt = 0;
// Creating tr's and td's
for($i = 1; $i <= 9; $i++) {
echo '<tr>';
for($h = 1; $h <= 18; $h++) {
$cell = $i.'-'.$h;
$pos = $ele[$cnt]['position'];
echo '<td id="'.$cell.'">';
if($pos == $cell) {
echo $ele[$cnt]['symbol'];
}
echo '</td>';
$cnt++;
}
echo '</tr>';
I hope you can help me, cus I'm pretty stuck.