Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/133813-need-some-help/
Share on other sites

<?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>";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/133813-need-some-help/#findComment-696871
Share on other sites

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. =\

Link to comment
https://forums.phpfreaks.com/topic/133813-need-some-help/#findComment-697256
Share on other sites

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>";
?>

Link to comment
https://forums.phpfreaks.com/topic/133813-need-some-help/#findComment-697266
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.