Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,585 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,960 people online right now. Registration is fast and FREE... Join Now!




Blog Archive issue

 
Reply to this topicStart new topic

Blog Archive issue

dimjaxor
29 Sep, 2008 - 04:20 PM
Post #1

New D.I.C Head
*

Joined: 10 Sep, 2008
Posts: 19

I am trying to make a blog archive unordered list that automatically adds dates from the database

Here's the database code
blogARCHIVEDATE is formatted like 200809 for September 2008
The database code works, it's an issue with the php code
CODE

$query_archiveDATE = "SELECT DISTINCT blogARCHIVEDATE FROM blog ORDER BY blogARCHIVEDATE DESC";
$archiveDATE = mysql_query($query_archiveDATE, $daveCONN);
$row_archiveDATE = mysql_fetch_assoc($archiveDATE);


Here's the php code, i know it's crazy and I could figure out a better way to do the month names instead of a huge elseif statement. I am new, I just kinda started writing the code hoping I could get it to work. Anyways when i preview in the browser, it's just a blank screen.
CODE

<ul>
<?php do { ?>
<?php
$year = substr($row_archiveDATE['blogARCHIVEDATE'], 0, 4);
$month = substr($row_archiveDATE['blogARCHIVEDATE'], 4, 2);
if $month = 01{
$monthname = "January";
} elseif $month = 02 {
$monthname = "February";
} elseif $month = 03 {
$monthname = "March";
} elseif $month = 04 {
$monthname = "April";
} elseif $month = 05 {
$monthname = "May";                  
} elseif $month = 06 {
$monthname = "June";                  
} elseif $month = 07 {
$monthname = "July";
} elseif $month = 08 {
$monthname = "August";                  
} elseif $month = 09 {
$monthname = "September";                  
} elseif $month = 10 {
$monthname = "October";                  
} elseif $month = 11 {
$monthname = "November";                  
} elseif $month = 12 {
$monthname = "December";                  
?>
<?php
if ($month < 10) {
$month = substr($month,1,1);
} else {
$month=$month;
}
?>
<li><a href=<?php echo "blog.php?bm=".$month."&by=".$year; ?>><?php echo $monthname." ".$year; ?> </a></li>
<?php } while ($row_archiveDATE = mysql_fetch_assoc($archiveDATE)); ?>
</ul>

The reason for <?php if $month < 10 ? substr($month,1,1) : $month=$month; ?> is because in the database the monts are single digits (except oct-dec obviously) instead of a 0.

Thanks,
Steve
User is offlineProfile CardPM
+Quote Post

dimjaxor
RE: Blog Archive Issue
29 Sep, 2008 - 04:25 PM
Post #2

New D.I.C Head
*

Joined: 10 Sep, 2008
Posts: 19

I changed all my if/elseif statements to having () now

so it's
CODE

if ($month = 01) {
$monthname = "January";
} elseif ($month = 02) {
$monthname = "February;
}

etc.

Still didn't work smile.gif

This post has been edited by no2pencil: 29 Sep, 2008 - 09:59 PM
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: Blog Archive Issue
29 Sep, 2008 - 05:00 PM
Post #3

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 580



Thanked: 59 times
Dream Kudos: 50
My Contributions
= is for assigning values, == is for comparing values
User is offlineProfile CardPM
+Quote Post

dimjaxor
RE: Blog Archive Issue
29 Sep, 2008 - 05:24 PM
Post #4

New D.I.C Head
*

Joined: 10 Sep, 2008
Posts: 19

ok i've narrowed it down to being an issue with the elseif

CODE

if ($month == 8) {
$monthname = "August";                  
}

that works...
NEVERMIND, just saw the stupid -- i put instead of == everything works fine now.
CODE

if ($month == 8) {
$monthname = "August";                  
} elseif ($month -- 9) {
$monthname = "September";
}

that doesn't...

and thanks for that reminder of the = is for assigning values, == is for comparing values

This post has been edited by dimjaxor: 29 Sep, 2008 - 05:25 PM
User is offlineProfile CardPM
+Quote Post

DilutedImage
RE: Blog Archive Issue
29 Sep, 2008 - 09:54 PM
Post #5

D.I.C Addict
Group Icon

Joined: 20 Nov, 2006
Posts: 642



Thanked: 6 times
Dream Kudos: 25
My Contributions
You might consider something like this ...

CODE
$month_text = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$month = intval("$month");
$monthname = $month_text[$month];

Should save at least a couple lines of code. smile.gif


User is offlineProfile CardPM
+Quote Post

dimjaxor
RE: Blog Archive Issue
30 Sep, 2008 - 04:18 AM
Post #6

New D.I.C Head
*

Joined: 10 Sep, 2008
Posts: 19

QUOTE(DilutedImage @ 29 Sep, 2008 - 10:54 PM) *

You might consider something like this ...

CODE
$month_text = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$month = intval("$month");
$monthname = $month_text[$month];

Should save at least a couple lines of code. smile.gif




Yah i knew there was a way to save some lines of code, just wanted to get it working. Thanks for the info! That works nicely! smile.gif
User is offlineProfile CardPM
+Quote Post

DilutedImage
RE: Blog Archive Issue
30 Sep, 2008 - 08:27 AM
Post #7

D.I.C Addict
Group Icon

Joined: 20 Nov, 2006
Posts: 642



Thanked: 6 times
Dream Kudos: 25
My Contributions
Happy to help.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:50AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month