Expand and collapsing

JavaScript related questions should go here.
Post Reply
User avatar
louiegiezer
Posts: 57
Joined: Fri Oct 21, 2011 11:31 am
Contact:

Expand and collapsing

Post by louiegiezer »

why does my javascript code expanding and collapsing not working inside of loop
[syntax=php]
<div id="categories">
<?php

$sel = "select * from `blog_cat`";
$cat = mysql_query($sel);

while($data = mysql_fetch_assoc($cat)){
echo "<a href='JavaScript:doMenu('main');' id=xmain>[+]</a>$data[name]";

$sel2 = mysql_query("SELECT * FROM `posts` WHERE `post_cid`='".$data['id']."'");
while($data2 = mysql_fetch_assoc($sel2)){

echo "
<div id=main style='margin-left:1em'>
<a href=#>$data2[post_title]</a><br>
</div>
<br>
";
}
}
?>
</div>
[/syntax]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Expand and collapsing

Post by jacek »

In what way does it not work ?

Also, you really should not be looping queries like that ! Have a look into using JOINs. Also it might be an idea to create a function to get the information you need instead of mixing up the HTML and logic like that.
Image
User avatar
louiegiezer
Posts: 57
Joined: Fri Oct 21, 2011 11:31 am
Contact:

Re: Expand and collapsing

Post by louiegiezer »

i remake this code it looks like creepy. i practice the sql join query and the function method. at this thread the problem is the javascript i think it is not compatible inside of loop statement. but when you removed to the sql query its working.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Expand and collapsing

Post by jacek »

louiegiezer wrote:i remake this code it looks like creepy. i practice the sql join query and the function method. at this thread the problem is the javascript i think it is not compatible inside of loop statement. but when you removed to the sql query its working.

I have no idea what you mean :?

Is it working ? :)

It won't be anything to do with the php, you will be making the html invalid in some way so a good step would be to make sure your html is valid.
Image
Post Reply