SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can someone tell me why this chunk of code doesn't work right??
    Code:
    while ($row = mysql_fetch_array($result)) {
    	if (end_date == "0000-00-00") {
    		echo "<b>".$row["beg_display"]."</b><br>";
    	} else {
    		echo "<b>".$row["beg_display"]." - ".$row["end_display"]."</b><br>";
    	}
    	echo $row["listing"]."<hr width=\"100%\">";
    }
    This is for a community calendar. Sometimes the event goes for more than one day so I want to reflect that in the display. I have beg_date (the first date of the event) and end_date (the last day of the event) and I am formatting both dates as beg_display and end_display. I want the code to show like this:
    If the event goes for more than one day, then show beg_display - end_display, if there is only one day in the event, then only show beg_display.

    The way the code up there is working right now, it show either no ending dates or it shows just the dash. Can someone help me out?

    ========================
    Also, what would be the easiest way of limiting the events shown on the calendar to a range of 30 days? So it would always show 30 days into the future from the current date (and older events would quietly disappear?
    <Edited by creole on 02-02-2001 at 12:46 PM>
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if (end_date == "0000-00-00")

    maybe

    if ($row["end_date"] == "0000-00-00")
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no...doesn't seem to be working properly. I have tried $end_display, $end_date, $row["end_date"] and nothing works. In the DB, the default for the date field is 0000-00-00 just like in my code. Why won't it work?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if the field is named end_display hten it should read

    $row["end_display"]

    What does your sql statement look like?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, here is the query that I am using.

    SELECT DATE_FORMAT(beg_date, '%M %d') AS beg_display, DATE_FORMAT(end_date, '%M %d') AS end_display, listing FROM kbxl_calendar ORDER BY beg_date ASC
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You see the problem lies with the fact that you are formatting the end_display so you your if() test does not match the format you are making in your query. try

    SELECT DATE_FORMAT(beg_date, '%M %d') AS beg_display, DATE_FORMAT(end_date, '%M %d') AS end_display, end_date, listing FROM kbxl_calendar ORDER BY beg_date ASC

    if ($row["end_date"] == "0000-00-00") {

    For the 30 day thing

    SELECT DATE_FORMAT(beg_date, '%M %d') AS beg_display, DATE_FORMAT(end_date, '%M %d') AS end_display, end_date, listing FROM kbxl_calendar WHERE beg_date < DATE_ADD(CURDATE(), INTERVAL 30 DAY) AND date > CURDATE() ORDER BY beg_date ASC
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy...that was it. After I read your last post, I realized that I wasn't using any variable called end_date. I was only using end_display. Once I added that, it worked beautifully. It's amazing the easy ones that you miss.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  8. #8
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was waiting for the infamous 'It worked' post. Now I can ask a question without interupting the conversation.

    When I use PHP in HTML I use <? and ?> to break from HTML and apply PHP to a page. This code has HTML tags built into the PHP. I'm assuming The " and . has a lot to do with it.

    Can you guys explain the code and possibly point me to some tutorials using this technique.

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the . is used to concatenate a variable or a function in php into the middle of another string however you can use vars inside of a double quotes just not single quotes so

    $name = "freddy";
    print "Hello my name is " . $name;
    print "Hello my name is $name";
    print 'Hello my name is ' . $name;

    Would both print
    Hello my name is freddy

    But
    print 'Hello my name is $name';

    would print
    Hello my name is $name

    Alternately you could use printf()

    printf('Hello my name is %s', $name)

    This would eleviate the need to use ." or .'

    Does this clear it up? I hope so.

    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •