1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to echo date in this

Discussion in 'PHP' started by webgames247, Feb 19, 2013.

  1. #1
    Hi,

    Newbie in Php..please help :)

    how do i echo this
    PHP:
    1. <?php echo $dateadded; ?>
    into this
    PHP:
    1. <item>
    2.   <title>'. $rss_row['title'] .'</title>
    3.   <description>'. $rss_row['description'] .'</description>
    4.  
    5.   <link>'. fileurl($rss_row['fileid'], $rss_row['title']) .'</link>
    6. </item>';
    Thanks advance
    Solved! View solution.
    webgames247, Feb 19, 2013 IP
  2. kulik

    kulik Member

    Messages:
    162
    Likes Received:
    18
    Best Answers:
    1
    Trophy Points:
    45
    #2
    If date added isn't in your database you can't echo or show anything. what are you asking exactly? You can't make a function or variable without defining what it does or is.
    You can store time in php to your database as time() then need a function to make it a "pretty time".
    kulik, Feb 19, 2013 IP
  3. webgames247

    webgames247 Member

    Messages:
    371
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #3
    The date is already in database and i just need to display the "$dateadded" to show the date
    webgames247, Feb 19, 2013 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,041
    Likes Received:
    41
    Best Answers:
    10
    Trophy Points:
    170
    #4
    Can't say for sure, but its going to be similar to what you have, something like
    <date>'. $rss_row['date'] .'</date>

    Open up your phpmyadmin and see what label the dateadded row is called.
    MyVodaFone, Feb 20, 2013 IP
  5. Graex

    Graex Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    23
    #5
    If the variable $dateadded already contains the date. Then just add it where you want it to be. Example below.

    Note: The position where I added it is likely not a good place. It is just to show how it is done.

    PHP:
    1.     <item> '.$dateadded.'
    2.       <title>'. $rss_row['title'] .'</title>
    3.       <description>'. $rss_row['description'] .'</description>
    4.    
    5.       <link>'. fileurl($rss_row['fileid'], $rss_row['title']) .'</link>
    6.     </item>';
    7.  
    This is the key part.
    PHP:
    1. '.$dateadded.'
    Graex, Feb 20, 2013 IP
  6. deathshadow

    deathshadow Prominent Member

    Messages:
    5,980
    Likes Received:
    827
    Best Answers:
    144
    Trophy Points:
    395
    #6
    What vodafone said sounds right to me too -- you say it's already in the database as part of the item, so it would be returned as a value in $rss_row

    I'm going to assume you are using RSS 2.0 and not Atom, since you're saying 'description' as a XML tag.

    In terms of keeping that valid for RSS 2.0
    Code (Text):
    1.     <item>
    2.         <title>' . $rss_row['title'] . '</title>
    3.         <datepub>' . $rss_row['date'] . '</datepub>
    4.         <description>' . $rss_row['description'] . '</description>
    5.         <link>' . fileurl($rss_row['fileid'], $rss_row['title']) .'</link>
    6.     </item>';
    Is where you'd plug in 'date' -- though again you need to know what that is called in the database those rows are being pulled from.

    Also if that's an echo instead of a string addition, swap out all those periods for comma's... just saying.

    However, if you actually HAVE a variable called 'dateadded' for whatever oddball reason, replace $rss_row['date'] with $dateadded.
    deathshadow, Feb 20, 2013 IP
  7. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,041
    Likes Received:
    41
    Best Answers:
    10
    Trophy Points:
    170
    #7
    ..and just to add, make sure your query actually calls the date for this specific result, as in, at the moment your query might only request title, description and link etc...
    MyVodaFone, Feb 20, 2013 IP
  8. webgames247

    webgames247 Member

    Messages:
    371
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #8
    PHP:
    1.     <item> '.$dateadded.'
    2.       <title>'. $rss_row['title'] .'</title>
    3.       <description>'. $rss_row['description'] .'</description>
    4.  
    5.       <link>'. fileurl($rss_row['fileid'], $rss_row['title']) .'</link>
    6.     </item>';
    7.  
    This is work but its very weird...i can see the month, date, years in the (view source code) but its blank on the page...anyone know why?

    Thanks
    webgames247, Feb 20, 2013 IP
  9. deathshadow

    deathshadow Prominent Member

    Messages:
    5,980
    Likes Received:
    827
    Best Answers:
    144
    Trophy Points:
    395
    #9
    Pay attention to mine -- You're building RSS 2.0 so EVERYTHING has to go in it's own tag. Dumping it in blindly like that is invalid XML and invalid RSS 2!

    You must use one of the official RSS2 tags -- datepub being the closest there is to dateadded. Date it was published... though you may also want <lastBuildDate>

    <datepub>'.$dateadded.'</datepub>

    Take a look at the specification and pay attention to the required and optional params.
    http://feed2.w3.org/docs/rss2.html#requiredChannelElements
    http://feed2.w3.org/docs/rss2.html#optionalChannelElements

    You may also want to htmlspecialchars all your fields in the output.
    deathshadow, Feb 21, 2013 IP
  10. #10
    May be you need to format date before output
    http://www.php.net/manual/en/function.date.php
    so the code for RSS will be like
    1. <?php echo date('D, d M Y h:i:s O', $dateadded); ?>
    sdeveloper, Feb 21, 2013 IP