Forum Moderators: coopster
---------------------------------------
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
// Create category/subcategory query.
$category_subcategory_query = "SELECT * FROM x_categories_subcategories WHERE x_categories_subcategories_id = '$row[1]'";
// Run query and assign returned result to variable.
$category_subcategory_result = @mysql_db_query(DB_NAME, $category_subcategory_query);
$category_subcategory_row = mysql_fetch_array( $category_subcategory_result, MYSQL_NUM);
$category = $category_subcategory_row[1];
$subcategory = $category_subcategory_row[2];
$categories_subcategories[$i] = array($category, $subcategory);
$i++;
}
// Alphabetize the category/subcategory results.
sort($categories_subcategories);
// Iterate through the categories/subcategories and insert them into the table.
foreach ($categories_subcategories as category_subcategory) {
foreach ($category_subcategory as $category => $subcategory) {
$bg = ($bg=='#eeeeee'? '#ffffff' : '#eeeeee'); // Alternate background color on each row.
echo '<TR BGCOLOR="', $bg, '">
<TD ALIGN="left">', $category, '</TD>
<TD ALIGN="left">', $subcategory, '</TD>
</TR>';
}
}
Category ¦ Subcategory
--------------------------
Category 01 ¦ Subcategory 03
Category 04 ¦ Subcategory 07
Category 08 ¦ Subcategory 09
Instead this is what is displaying (note the keys displaying in the left column and all values being pushed into the second column):
Category ¦ Subcategory
--------------------------
0 ¦ Category 01
1 ¦ Subcategory 03
0 ¦ Category 04
1 ¦ Subcategory 07
0 ¦ Category 08
1 ¦ Subcategory 09
The lines don't match up well in these examples but I tried to show the two colums as well as the board would let me. Sorry I didn't include a good example earlier - my mind had been reduced to mush by the time I threw up my arms and decided to ask for help : ) Thanks!
x_categories
autoinc_id,x_category_name ...
x_categories_subcategories
autoinc_id,x_categories_subcategories_id,x_categories_subcategory_name ...
where x_categories_subcategories.x_categories_subcategories_id = x_categories.x_category_name
Something like that? It would help if you would post a couple of rows of data similar to one used in your example.