I have this
if (mysqli_num_rows($bay_result) > 0) {
while($bays = mysqli_fetch_assoc($bay_result)) {
echo '<rect x="'.$bays['x_coord'].'" y="'.$bays['y_coord'].'" width="'.$bays['width'].'" height="'.$bays['height'].'" class="bay" />';
echo '<a xlink:href="../racks/add_rack.php?RoomID=2&Row=1&Bay='.$bays['title'].'">';
echo '<text x="'.($bays['x_coord'] + 15).'" y="'.($bays['y_coord'] + 47).'" class="bay_text">'.$bays['title'].'</text>';
echo '</a>';
}
}
which results in
So the query works perfect and returns the bays (the boxes with blue leters in groups of 10) in 5 ddifferent rows.
What id like to dois make the query whange the Row variariable in the link (?Row=1) change depending on which row (1-5) its in.
I think I have to split the results of the query into groups of 10.
How can I do that?
I was thinking Can I put the result into an array, then put that into a for loop like,
$bays_array = array();
while($bays = mysqli_fetch_array($bay_result)) {
//populate the aray
}
foreach($bays_array as $bays) {
for ($x = 0; $x <= 10; $x++) {
echo '<rect x="'.$bays['x_coord'].'" y="'.$bays['y_coord'].'" width="'.$bays['width'].'" height="'.$bays['height'].'" class="bay" />';
echo '<a xlink:href="../racks/add_rack.php?RoomID=2&Row=1&Bay='.$bays['title'].'">';
echo '<text x="'.($bays['x_coord'] + 15).'" y="'.($bays['y_coord'] + 47).'" class="bay_text">'.$bays['title'].'</text>';
echo '</a>';
}
for ($x = 0; $x <= 10; $x++) {
echo '<rect x="'.$bays['x_coord'].'" y="'.$bays['y_coord'].'" width="'.$bays['width'].'" height="'.$bays['height'].'" class="bay" />';
echo '<a xlink:href="../racks/add_rack.php?RoomID=2&Row=2&Bay='.$bays['title'].'">';
echo '<text x="'.($bays['x_coord'] + 15).'" y="'.($bays['y_coord'] + 47).'" class="bay_text">'.$bays['title'].'</text>';
echo '</a>';
}
for ($x = 0; $x <= 10; $x++) {
echo '<rect x="'.$bays['x_coord'].'" y="'.$bays['y_coord'].'" width="'.$bays['width'].'" height="'.$bays['height'].'" class="bay" />';
echo '<a xlink:href="../racks/add_rack.php?RoomID=2&Row=3&Bay='.$bays['title'].'">';
echo '<text x="'.($bays['x_coord'] + 15).'" y="'.($bays['y_coord'] + 47).'" class="bay_text">'.$bays['title'].'</text>';
echo '</a>';
}
for ($x = 0; $x <= 10; $x++) {
echo '<rect x="'.$bays['x_coord'].'" y="'.$bays['y_coord'].'" width="'.$bays['width'].'" height="'.$bays['height'].'" class="bay" />';
echo '<a xlink:href="../racks/add_rack.php?RoomID=2&Row=4&Bay='.$bays['title'].'">';
echo '<text x="'.($bays['x_coord'] + 15).'" y="'.($bays['y_coord'] + 47).'" class="bay_text">'.$bays['title'].'</text>';
echo '</a>';
}
for ($x = 0; $x <= 10; $x++) {
echo '<rect x="'.$bays['x_coord'].'" y="'.$bays['y_coord'].'" width="'.$bays['width'].'" height="'.$bays['height'].'" class="bay" />';
echo '<a xlink:href="../racks/add_rack.php?RoomID=2&Row=5&Bay='.$bays['title'].'">';
echo '<text x="'.($bays['x_coord'] + 15).'" y="'.($bays['y_coord'] + 47).'" class="bay_text">'.$bays['title'].'</text>';
echo '</a>';
}
}
Is this somewhat right?