Jump to content

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>';
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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