Jump to content

Only show one date for links-list


ManInBlack

Recommended Posts

Hi. I'm making a website like www.evilhumor.com ...

 

I really don't know how I have this Date just show one time for every links for this day.

 

http://pastebin.com/m1647e0ea

 

Like I want have it.

2 jan.

cat - sometext for url

cat - sometext for url

cat - sometext for url

 

1 jan.

cat - sometext for url

cat - sometext for url

cat - sometext for url

 

It's like now

 

cat - sometext - date

cat - sometext - date

cat - sometext - date

 

sorry my english, can someone understand want I mean?

Link to comment
https://forums.phpfreaks.com/topic/172471-only-show-one-date-for-links-list/
Share on other sites

$query = '... ORDER BY date DESC';//!important

$currentDate = '';
while ($row = mysql_fetch_assoc($result)) {
    if ($currentDate !== $row['date']) {
         echo $row['date'], '<br>';
         $currentDate = $row['date'];
    }
    echo $row['cat'], ' ', $row['sometext_for_url'], '<br>';
}

$query = '... ORDER BY date DESC';//!important

$currentDate = '';
while ($row = mysql_fetch_assoc($result)) {
    if ($currentDate !== $row['date']) {
         echo $row['date'], '<br>';
         $currentDate = $row['date'];
    }
    echo $row['cat'], ' ', $row['sometext_for_url'], '<br>';
}

 

Thx for the answer, Maybe I'm doing some wrong here in my code.

Can you help me more, and tell me what is wrong I'm doing?

 

Dagstimi = date // flokkur = cat

 

 

 

<?php
if (!empty($_GET["flokkur"])) 
{ 
$flokkur = mysql_real_escape_string($_GET["flokkur"]); 

$result = mysql_query("SELECT flokkur,dagstimi FROM tenglar WHERE flokkur = '$flokkur' ORDER BY dagstimi DESC");

while ($row = mysql_fetch_assoc($result)) {
$currentDate = '';
if ($currentDate !== $row['dagstimi']) {
         echo $row['dagstimi'], '<br>';
         $currentDate = $row['dagstimi'];
    }
echo "<div class='tenglalisti'><img src='img/arrow.gif' width='8' height='8' /> ";
echo $row['flokkur'];
echo "<br /> </div>";
}

}

else { 
$result = mysql_query("SELECT flokkur,dagstimi FROM tenglar ORDER BY dagstimi DESC");
while ($row = mysql_fetch_assoc($result)) {
$currentDate = '';
if ($currentDate !== $row['dagstimi']) {
         echo $row['dagstimi'], '<br>';
         $currentDate = $row['dagstimi'];
	 }
echo "<div class='tenglalisti'><img src='img/arrow.gif' width='8' height='8' /> ";
echo $row['flokkur'];
echo "<br /> </div>";
}
}
?>	

 

I'm

Please if you copy my code then copy it exactly:

 

while ($row = mysql_fetch_assoc($result)) {
$currentDate = '';//this will reset $currentDate on each loop
if ($currentDate !== $row['dagstimi']) {

 

Should be:

 

$currentDate = '';
while ($row = mysql_fetch_assoc($result)) {
    if ($currentDate !== $row['dagstimi']) {

 

As in:

 

$query = '... ORDER BY date DESC';//!important

$currentDate = '';
while ($row = mysql_fetch_assoc($result)) {
    if ($currentDate !== $row['date']) {
         echo $row['date'], '<br>';
         $currentDate = $row['date'];
    }
    echo $row['cat'], ' ', $row['sometext_for_url'], '<br>';
}

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.