Page 1 of 1

Filter down to one heading

Posted: Tue Nov 04, 2008 10:02 am
by Addos
Within the loop below I only want to return echo "<br><h1>Future Engag</h1>"; once so that it displays better on the webpage. As it stands it naturally returns ‘Future Engag’ for each iteration of the loop for example

Future Engag
Today
Future Engag
Tomorrow
Future Engag
Next week

When I really need

Future Engag
Today
Tomorrow
Next week

How do I filter this out? I have been trying to use something like this in an array

// If any of the values are repeated set message.
if ($occurences > 1) {
echo Future Engag;

But this is still not working for me
Thanks for any pointers

Code: Select all

// Look for future dates 2009 2010 etc  
           do {
  
    echo  "<br><h1>Future Engag</h1>"; ?>
    
        <a href="future.php?id=<?php echo $row_GetEngag['eng_id']; ?>">                  <?php echo $row_GetEngag['head']; ?></a><br />
    
       <?php } while ($row_GetEngag = mysql_fetch_assoc($GetEngag)); ?> 

Re: Filter down to one heading

Posted: Tue Nov 04, 2008 2:51 pm
by Jade
Your logic is incorrect. Print the header, then all the links for that header.

Code: Select all

 
<?php
echo  "<br><h1>Future Engag</h1>";
 
      do {
        echo "<a href=\"future.php?id=" . $row_GetEngag['eng_id'] . "\">" . $row_GetEngag['head'] . "</a><br />";
       } while ($row_GetEngag = mysql_fetch_assoc($GetEngag)); 
?> 
 

Re: Filter down to one heading

Posted: Tue Nov 04, 2008 4:26 pm
by Addos
Thanks for the reply.
Yeah I understand what you mean however I need this heading ‘Future Engag’ to only show if there are any dates in the database for coming year(s) and if there isn’t then it’s not needed.

The full code I’m using for this is as follows as I left out some in the pervious post as I thought it might not be necessary.
Any further thoughts?
Thanks

Code: Select all

// Look for future dates 2009     
           do {
 
 $date = $row_GetEngag['heading'];
  ($date_new = substr($date, -4) ); 
   if($date_new > date("Y")){   
    
    echo "<br><h1>Future Engag</h1> "; ?>
    
        <a href="engagements_future.php?id=<?php echo $row_GetEngag ['engage_id']; ?>">                  <?php echo $row_GetEngag ['heading']; ?></a><br />
    <?PHP } ?>    
       <?php } while ($row_GetEngag = mysql_fetch_assoc($GetEngag)); ?> 

Re: Filter down to one heading

Posted: Tue Nov 04, 2008 4:38 pm
by Jade
That's fine if you need it based off of a date. It still works the same way...

Code: Select all

 
<?php
 
//first find out if you need to display the heading
$row_GetEngag = mysql_fetch_assoc($GetEngag);
 
$date = $row_GetEngag['heading'];
$date_new = substr($date, -4);
 
if($date_new > date("Y"))
   echo  "<br><h1>Future Engag</h1>";
 
//then echo all the items under that heading
      while ($row_GetEngag = mysql_fetch_assoc($GetEngag))
        echo "<a href=\"future.php?id=" . $row_GetEngag['eng_id'] . "\">" . $row_GetEngag['head'] . "</a><br />";
?>