Hello all,
I have a Table1 to display given categories, and a Table2 to display items for each of those categories. I wrote the following in hopes to increment ($i) each item, in order to create a div id, for later reference/toggling.
[php]/******
Cont’d from while($row = category results from Table1 {
//display each category and build jscript ($tog) for toggling…
******/
//select items per category using common id
$get_items = “SELECT * FROM Table2 WHERE item_cat = {$row[‘cat_id’]}”;
$i_result = $conn->query($get_items) or die(‘oops’);
// count cat items for incrementing later
$i_cnt = $i_result->num_rows;
//now complete code build
while($i_row = $i_result->fetch_assoc()) {
// add # for toggling div id’s
for ($i = 1;$i<$i_cnt+1;$i++) {
$tog .= ’
//toggle individual items
jQuery("#id’.$category."".$i.’").hide();
//toggle the componenet with class msg_body
jQuery("#tog’.$category."".$i.’").click(function()
{
jQuery("#optns’.$category."".$i.’").slideToggle(500);
jQuery("#open’.$category."".$i.’").slideToggle(100);
jQuery("#close’.$category."_".$i.’").slideToggle(100);
});’;
} //end for $i
}//end while ($i_row
} //end while ($row
$tog .= ’
});
';
echo $tog;//echo the built jscript for action[/php]
The problem I’m having is that the output contains the incremented items per category, but as many times as per item. For example, if Category A has 5 items, then the code shows 5 increments for those items (as intended) under said category… BUT FIVE TIMES instead of just incrementing through them once, like this:
[code]
//toggle individual items for categoryA
jQuery("#id_catA_1").hide();
//toggle the componenet with class msg_body
jQuery("#tog_catA_1").click(function()
{
jQuery("#id_catA_1").slideToggle(500);
jQuery("#open_catA_1").slideToggle(100);
jQuery("#close_catA_1").slideToggle(100);
});
//toggle individual items for categoryA
jQuery("#id_catA_2").hide();
//toggle the componenet with class msg_body
jQuery("#tog_catA_2").click(function()
{
jQuery("#id_catA_2").slideToggle(500);
jQuery("#open_catA_2").slideToggle(100);
jQuery("#close_catA_2").slideToggle(100);
});
//this continues on until #id_catA_5 and then it repeats all of this 4 more times…
//toggle individual items for categoryA
jQuery("#id_catA_1").hide();
//toggle the componenet with class msg_body
jQuery("#tog_catA_1").click(function()
{
jQuery("#id_catA_1").slideToggle(500);
jQuery("#open_catA_1").slideToggle(100);
jQuery("#close_catA_1").slideToggle(100);
});
//toggle individual items for categoryA
jQuery("#id_catA_2").hide();
//toggle the componenet with class msg_body
jQuery("#tog_catA_2").click(function()
{
jQuery("#id_catA_2").slideToggle(500);
jQuery("#open_catA_2").slideToggle(100);
jQuery("#close_catA_2").slideToggle(100);
});
{[/code]
I’ve tried moving the [php]for ($i=1;$<…[/php] statement to live before the [php]while($i_row…[/php]statement. But then everything gets a number 1 as its increment
Can anybody see where my problem is? Thanks in advance