I need to break up an array into chunks, but it's the result of a mysql query that contains multiple values. It looks like this:
$minQuery = "SELECT typeName, typeID FROM invTypes WHERE groupID = '18'";
$con = mysqli_connect('127.0.0.1', $username, $password, 'sdeodyssey107');
$result = mysqli_query($con,$minQuery);
What I need to do is to be able to break this result up into rows of 3 at a time. I can't seem to find a way to get array_chunk to work with the multiple values, and everything I have tried with while loops ends up with me repeating the same value multiple times per row.
Anyone know a good way to handle this? The line that will be printed looks like this:
echo '<td align="right">' . $typeName . ': <input type="text" size="25" name="' . $typeName . '|' . $itemID . '"';if(isset($_GET["$cleanTypeName|$itemID"])) echo 'value="'.$_GET["$cleanTypeName|$itemID"].'"';echo '></td>';
...so I need to have both values available each time I call the function that prints those lines....
<?php
$i = 1;
$count = count($result) - 3;
echo '<tr/>';
foreach($result as $key => $value)
{
if ($i % 3 === 0 && $i > 3) echo '<tr>';
foreach ($value as $subKey => $subValue)
{
echo '<td align="right">' . $value['typeName'] . ': <input type="text" size="25" name="' . $value['typeName'] . '|' . $value['itemID'] . '"';if(isset($_GET["$cleanTypeName|$itemID"])) echo 'value="'.$_GET["$cleanTypeName|$itemID"].'"';echo '></td>';
}
if ($i % 3 === 0 && $i < $count) echo '</tr>';
$i++;
}
echo '</tr>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.