I'm trying to retrieve information from 2 tables in my DB and make it output into a table.. but the information from the nested loop (echo "<td>".$col2[$row['Group_ID']]."</td>"😉 won't display. Here's the code that I've got:
$sql = "SELECT * FROM ".$db_table_prefix."Pages ORDER BY Page";
$result = $db->sql_query($sql);
while ($col = $db->sql_fetchrow($result)) {
echo "<td>".$col['Page']."</td>";
}
echo "</tr>";
$sql = "SELECT * FROM ".$db_table_prefix."Groups ORDER BY Group_ID";
$result2 = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result2)) {
echo "<tr><td>".$row['Group_Name']."</td>";
while ($col2 = $db->sql_fetchrow($result)) {
echo "<td>".$col2[$row['Group_ID']]."</td>";
}
echo "</tr>";
}
Now, I can make this code work by adding in another DB access before the nested loop like this:
$sql = "SELECT * FROM ".$db_table_prefix."Pages ORDER BY Page";
$result = $db->sql_query($sql);
while ($col = $db->sql_fetchrow($result)) {
echo "<td>".$col['Page']."</td>";
}
echo "</tr>";
$sql = "SELECT * FROM ".$db_table_prefix."Groups ORDER BY Group_ID";
$result2 = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result2)) {
echo "<tr><td>".$row['Group_Name']."</td>";
$sql = "SELECT * FROM ".$db_table_prefix."Groups ORDER BY Group_ID";
$result2 = $db->sql_query($sql);
while ($col2 = $db->sql_fetchrow($result)) {
echo "<td>".$col2[$row['Group_ID']]."</td>";
}
echo "</tr>";
}
But I'd prefer it not to access my DB again every time the loop runs. Any help would be appreciated.