ManInBlack Posted August 30, 2009 Share Posted August 30, 2009 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 More sharing options...
ignace Posted August 30, 2009 Share Posted August 30, 2009 $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>'; } Link to comment https://forums.phpfreaks.com/topic/172471-only-show-one-date-for-links-list/#findComment-909274 Share on other sites More sharing options...
ManInBlack Posted August 30, 2009 Author Share Posted August 30, 2009 $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 Link to comment https://forums.phpfreaks.com/topic/172471-only-show-one-date-for-links-list/#findComment-909357 Share on other sites More sharing options...
ignace Posted August 31, 2009 Share Posted August 31, 2009 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>'; } Link to comment https://forums.phpfreaks.com/topic/172471-only-show-one-date-for-links-list/#findComment-909562 Share on other sites More sharing options...
ManInBlack Posted September 1, 2009 Author Share Posted September 1, 2009 Thank You! Link to comment https://forums.phpfreaks.com/topic/172471-only-show-one-date-for-links-list/#findComment-910478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.