Jump to content

Need Some Help


yarub

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.