Okay, so here's my problem: I want to store the results of a MySQL query as a multidimensional array. This is for the purpose of eliminating an unneeded query.
Basically, I'm pulling info from my database. At a later point I need to retrieve the name of a tab based on its id in the database. I'm thinking if I had the variable as something like this:
$row['2']['name'];
It would then show as the name of the tab with an id of 2. Anyone know how this can be done? Got any other ideas? It just seems I have an extra query I can get rid of.
Here's where my code stands now, if it matters:
$sql = "SELECT id, name, position, compulsive FROM phpbb_nulavatar_layers ORDER BY position";
$result = mysql_query($sql);
if ( $row_count = mysql_num_rows( $result )) {
$row = mysql_fetch_assoc($result);
if ( !row ) {
echo "There was an error.";
}
else {
extract( $row );
}
}
else {
echo "No layers detected.";
}
echo "<ul>";
for ( $i = 1; $i <= $row_count; $i++ ) {
$sql2 = "SELECT name FROM phpbb_nulavatar_layers WHERE id = " . $i . "";
$result2 = mysql_query($sql2);
$row2 = mysql_fetch_assoc($result2);
extract( $row2 );
echo "<li><a href=\"tabs_select.php?tab=" . $i . "\"><span>" . $name . "</span></a></li>
";
}
echo "</ul>