ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Almost there...just need help limiting number of queries

February 13, 2009 12:39pm

Subscribe [1]
  • #1 / Feb 13, 2009 12:39pm

    stephlivsey

    16 posts

    Hi.

    I am using a SQL query to display information from my database.  Everything is working fine; however, I can’t find a way to limit the entries displayed to those submitted in just the last month. 

    I tried to use the weblog display_by=“week” limit=“4” code, but that doesn’t work.  Here’s my current query; any help would be appreciated!!

    {exp:query sql="SELECT exp_freeform_entries.tribute, exp_freeform_entries.type, exp_freeform_entries.text, exp_freeform_attachments.filename, exp_freeform_attachments.extension FROM exp_freeform_entries, exp_freeform_attachments WHERE exp_freeform_entries.entry_id = exp_freeform_attachments.entry_id ORDER BY exp_freeform_entries.entry_date DESC"}
    
    <h5>{type} {tribute}</h5>
    <blockquote><p>{text}<br />
    <a href="http://sabarfoundation.org/SABF/images/freeform/{filename}{extension}">http://sabarfoundation.org/SABF/images/freeform/{filename}{extension}</a></p>
    </blockquote>
    
    <p>{/exp:query}

  • #2 / Feb 13, 2009 12:54pm

    ender

    1644 posts

    there’s a million and one ways to write the SQL for such a thing, but knowing that EE stores everything as unix timestamps (unrelated: why not use mysql datetime fields for this?) adding something like this to your query should work:

    exp_freform_entries.entry_date > UNIX_TIMESTAMP()-2592000

    2592000 = 60*60*24*30 = 30 days worth of unix time.

  • #3 / Feb 13, 2009 1:06pm

    stephlivsey

    16 posts

    oooh, I think that will work.  I just put the extra line into my query like this:

    WHERE exp_freeform_entries.entry_id<>exp_freeform_attachments.entry_id AND exp_freeform_entries.entry_date > UNIX_TIMESTAMP()-172800

    Nothing has been removed (which it shouldn’t yet); but, if I did my calculations correctly, my entries should be deleted after 2 days 60*60*24*2
    Hope I did that correct; I’ll post in two days to see if this worked. Then, I’ll edit my code again to remove the entries after 30 days.

    THANK YOU!!

  • #4 / Feb 16, 2009 10:41am

    stephlivsey

    16 posts

    Just wanted to post a quick update:  This worked PERFECTLY!!! Thank you 😊

  • #5 / Feb 16, 2009 11:00am

    ender

    1644 posts

    no problem, glad to help.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases