<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>
Expand and collapsing
- louiegiezer
- Posts: 57
- Joined: Fri Oct 21, 2011 11:31 am
- Contact:
Expand and collapsing
why does my javascript code expanding and collapsing not working inside of loop
Re: Expand and collapsing
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.
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.
- louiegiezer
- Posts: 57
- Joined: Fri Oct 21, 2011 11:31 am
- Contact:
Re: Expand and collapsing
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.
Re: Expand and collapsing
I have no idea what you meanlouiegiezer 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.
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.