I can't get my head around them.
I have two MySQL tables, one contains the categories, the other contains
the posts. Each post is linked to a category.
Now I'm trying to display each post with a drop down menu that has the
categories in it and have the category that the post is in selected.
Here's my code for the drop down menu where my woes lie.
for ($i=0; $i<count($posts); $i++) {
for ($j=1; $j<=count($categories); $j++) {
if ($j == $post[$i]['id']) {
selected = ' selected="selected"';
} else {
selected = '';
}
$category_list .= '<option value="' . $j . '"' . $selected . '>' . $cat_name[$j] . '</option>';
}
unset($j);
$dropdown .= '<td><select name="' . $cat_name[$i]['name'] . '">'. $category_list . '</select></td>';
}
Here's my problem, for ease, lets say I have 2 categories and 100 posts.
For post one I have 2 categories in the menu. For the next post I have 4
categories in the menu (the 2 have been doubled), for the third I have 6
(tripled), and so on.
Each post after the next has another 2 categories added. So the drop down
menu for post 100 has 200 categories listed. Just the same two repeated
over and over.
The output should look like this, though an <option> for each category,
but just two for this example.
<td><select name="post1"><option value="1" selected="selected">Cat Name 1</option><option value="2">Cat Name 2</option></select></td>
I've been trying all sorts of things, but nothing seems to work correctly.
Can anyone see where I'm going wrong with my loops? I'm going loopy here
trying to figure it out. :)
Thx
Marc :O)