Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No output for multiple columns 4

Status
Not open for further replies.

dmacster

Technical User
Jan 28, 2005
670
US
I've tried to add in some code from jpadie to the output I have that did work, but I get no output at all now. Can someone point out what I've screwed up, please?

Here 'tis
Code:
<?php require_once("includes/connection.php"); ?>

  <?php 
  $numColumns = 4;
  
   //CREATE THE SQL QUERY TO PULL ALL VISIBLE LISTINGS
   
   $sql = "select * from advertisers a left join category c USING(category_id) ";
   $sql .= "WHERE a.visible = 1 order by c.category_name asc, a.advertiser_name asc ";

   $result = mysql_query($sql);
   $count = mysql_num_rows($result);
   
   $currentCategory = "";
   
   //start output
if ($count > 0){
    echo "\r\n";
} else {
    die ('no records found');
}

   while($row = mysql_fetch_array($result)){
   
      //PRINT OUT THE CATEGORY NAME EVERY TIME IT CHANGES
          //start the inner loop
    for ($i=0; $i<$numColumns; $i++){
        if ($currentCategory == "" || $currentCategory != $row['category_id']){
         echo "<div class='categoryName' style='font-weight:bold;margin-top:8px;'>";
         echo "<a href='category.php?cid=".$row['category_id']."'>" .stripslashes($row['category_name'])."</a></div>";
         $currentCategory = $row['category_id'];
      }
	  else {
            //prevent broken end columns
            echo "\r\n";
        }
      
      //PRINT OUT THE ADVERTISER
      echo "<div class='advertiserName'>";
      echo "<a href='category.php?cid=".$row['category_id']."#advertiser_".$row['advertiser_id']."'>";
      echo stripslashes($row['advertiser_name']);
      echo "</a></div>";
   }
   
?>

Thanks,
Donna
 
no need to apologise. it's threads like these that benefit future readers the most.
 
I tried the table version, and it works, but I need to try to figure out how to move the category into its own cell, because it gives some weird spacing. See example
I think the css version would be the way to go, except I only get one column. See that exampe
Am I missing an output or do I need another div somewhere?

Thanks,
Donna
 
Sorry - please ignore the part above about moving the category into its own cell - that would still leave weird spacing since a row with a category name on the left and an advertiser name on the right would have different padding above.

I'll try working on the css version. I'll just have to recreate the shell I was provided by the client (it's pretty ugly, but that's what they've got).

Thanks,
Donna
 
add a css class declaration
CSS:
.column {width:24%; float:left; margin-left: 5px; min-width: 200px;}

for some reason it got missed off the cut and paste.

you're right about the spacing on the table method, but i'm sure you can fix that with some judicious css.
 
Thanks - I should have picked up on that even though it was late.

I think I'll recreate the provided page and use the css.

I went around with the table version styles for a bit and could probably fake it out, if it comes to that.

Thanks again, jpadie.
 
on the tables - it's not the style that's causing the problem. it's that in some cases the cell has two bits of data and in other it has but one. because the rows need to line up nicely across the table, there will inevitably be extra space from time to time.
the solution is to give the category headings their own cell. But then you would also need to know the number of categories in the data. not difficult to do.
 
Thanks. I just got home. I know there are a set number of categories, but not all categories may be visible (i.e., some weeks may have no one visible in that category).

The people are trying to decide on everything now - I think I'll end up changing over the weekend depending on their meeting.

Yup - after checking source I could see the category ended up with one advertiser in a cell making the strange spacing. That's why I think I'll end up using the css version - I actually understand that a bit more - at least as far as design.

Thanks,

Donna
 
the only caveat with the css method is that it does not degrade neatly if you narrow the width. the columns 'jump' under each other and there is not guarantee that they will do so in a way that is contiguous with the previous column.

i have 'fixed' this by specifying a pixel amount (rather than percentage) for width and min-width.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top