yarub Posted November 22, 2008 Share Posted November 22, 2008 Couldn't think of a good name for a subject. Oh well. What I'm trying to do is print out a list of categories.. but it would almost require a query within a query to do this.. and I can't figure it out. I'm goin nuts. Here's what it looks like... <div class='details'> <ul class='categories'> <li><a href='#' class='nav_categories'>Category 1</a></li> <li><a href='#' class='nav_categories'>Category 2</a></li> <li><a href='#' class='nav_categories'>Category 3</a></li> </ul> </div> <div class='details'> <ul class='categories'> <li><a href='#' class='nav_categories'>Category 4</a></li> <li><a href='#' class='nav_categories'>Category 5</a></li> <li><a href='#' class='nav_categories'>Category 6</a></li> </ul> </div> How can I get it to print out so that each "Category" is a separate row from the database. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/133813-need-some-help/ Share on other sites More sharing options...
yarub Posted November 23, 2008 Author Share Posted November 23, 2008 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/133813-need-some-help/#findComment-696838 Share on other sites More sharing options...
redarrow Posted November 23, 2008 Share Posted November 23, 2008 <?php // database connection... $sql="select * from what_ever"; $res=mysql_query($sql)or die(mysql_error()); while($data=mysql_fetch_assoc($res)){ echo"<div class='details'> <ul class='categories'> <li><a href='".$data['url']." class='Category'>".$data['Category']."</a></li> </ul> </div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/133813-need-some-help/#findComment-696871 Share on other sites More sharing options...
yarub Posted November 23, 2008 Author Share Posted November 23, 2008 That's not going to work though because it's not going to place the fields in the right area. I need it to be able to put four in each list, then break off into another set of four.. then another. And so on. <div class='details'> <ul class='categories'> <li><a href='#' class='nav_categories'>Category 1</a></li> <li><a href='#' class='nav_categories'>Category 2</a></li> <li><a href='#' class='nav_categories'>Category 3</a></li> <li><a href='#' class='nav_categories'>Category 4</a></li> </ul> </div> <div class='details'> <ul class='categories'> <li><a href='#' class='nav_categories'>Category 5</a></li> <li><a href='#' class='nav_categories'>Category 6</a></li> <li><a href='#' class='nav_categories'>Category 7</a></li> <li><a href='#' class='nav_categories'>Category 8</a></li> </ul> </div> <div class='details'> <ul class='categories'> <li><a href='#' class='nav_categories'>Category 9</a></li> <li><a href='#' class='nav_categories'>Category 10</a></li> <li><a href='#' class='nav_categories'>Category 11</a></li> </ul> </div> It could look like that. So it's not simply done with one while query thinger.. Takes more than that. =\ Quote Link to comment https://forums.phpfreaks.com/topic/133813-need-some-help/#findComment-697256 Share on other sites More sharing options...
sasa Posted November 23, 2008 Share Posted November 23, 2008 try <?php // database connection... $sql="select * from what_ever"; $res=mysql_query($sql)or die(mysql_error()); $i =0; while($data=mysql_fetch_assoc($res)){ if ($i % 4 == 0) echo "<div class='details'> <ul class='categories'> "; $i++; echo" <li><a href='".$data['url']." class='Category'>".$data['Category']."</a></li>"; if ($i %4 == 0) echo" </ul> </div>"; } if ($i %4 > 0) echo" </ul> </div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/133813-need-some-help/#findComment-697266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.