Hey there, I need some help with my php script. It's designed to put in entries/links under a headline which is the day they were added into the database. So it looks like this for example: 2008-09-25 entry4 2008-09-24 entry3 entry2 entry1 and so on, however my problem is that I can't figure out a way to put a </div> where the entries stop for the day. I wan't it to be so that I can manipulate all the entries for one day seperately and so on. Here's my code. $olddate= ""; ?> <div class="holder2"> <?php while($row = mysql_fetch_array($result)) { list($id, $rubrik, $embedurl, $lankurl, $klick, $date, $tid, $kat, $tipsare) = $row; $qcount = mysql_query("SELECT * FROM kommentarer where nid='".$row['id']."'"); $scount = mysql_num_rows($qcount); if($olddate != $date) { $olddate = $date; ?> <div class="dateholder"><p><?php echo $date; ?></p></div> <?php } // end if ?> <div class="linkholder"> <ul> <?php if($embedurl != '') { ?> <li><a href="lank.php?id=<?php echo $id; ?>" target="_blank"><?php echo $rubrik;?></a></li> <?php } else { ?> <li><a href="redir.php?id=<?php echo $id; ?>" target="_blank"><?php echo $rubrik;?></a></li> <?php } ?> <li><small><?php echo $tid;?></small></li> <li><a href="#" onClick="window.open('kommentar.php?id=<?php echo $id; ?>','mywindow','width=350,height=400')"><?php echo $scount;?> Inlägg</a></li> <li>Klick: <?php echo $klick;?></li> <li>Kategori: <?php echo $kat;?></li> <li>Tipsare: <?php echo $tipsare;?></li> <li>Rating: <?php echo rating_bar($id,'5'); ?></li> </ul> </div> <?php if($olddate != $date) { ?> <h1>TEST</h1> <?php } } // end while } ?> </div> PHP:
erm if($olddate != $date) { $olddate = $date; ... so it goes in and sets to same then at bottom you go: if($olddate != $date) { ?> <h1>TEST</h1> <?php } even if they did differ, they don't anymore. you kind of need to move this print above the first if .
well, you can do it before something like <? $first = true; while ( ) { ... if ($olddate != $date) { if ($first) // on the first loop iteration, don't close a layer (not open yet) $first = !$first; else echo '</div>'; echo '<div class="dateholder"><p>...'; } // end while echo "</div>"; // close last div. ?> PHP:
Thanks! I'll see if it works later. Looks promising though. Why is the first </div> right after else in there though? Is that the one that closes the last entry for the previous day?
correct. but on the very first loop iteration, there has not been a previous entry. this will prevent you form closing the parent div inadvertently