WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Be nice and help a newbie with php/mysql (8 posts)

  1. 3stripe
    Member
    Posted 8 years ago #

    Hello folks,

    I'm using WordPress to update a Flash news feed. The mySQL post data is fed directly into Flash via a simple php file.

    It was working fine, until I added images to the mix, using the "Meta Image" plugin...(http://no.oneslistening.com/151)

    Now it seems that images which don't have a meta image don't show up in my list of articles.

    So at http://www.thirdeyedesign.co.uk/news/wptest3.html you can't see the third story, because it doesn't have an image.

    So, if anyone could help me tweak my code so that posts without an image show up, I would be very very grateful!

    mysql_select_db ("wordpress");
    $qResult = mysql_query ("SELECT * FROM wp_posts, wp_post2cat, wp_postmeta, wp_categories WHERE wp_posts.ID=wp_post2cat.post_id AND wp_post2cat.post_id=wp_postmeta.post_id AND wp_posts.post_status='publish' AND wp_post2cat.category_id=wp_categories.cat_ID AND wp_categories.cat_name='$category' ORDER BY ID DESC");

  2. 3stripe
    Member
    Posted 8 years ago #

    Ps. I have tried removing 'wp_post2cat.post_id=wp_postmeta.post_id' - but when I do this, I get multiple instances of each story appearing in the list of headlines - so it seems to mess something up.

  3. VaamYob
    Member
    Posted 8 years ago #

    Try this, it'll return posts regardless of wether or not there are any corresponding wp_postmeta records:


    $qResult = mysql_query ("SELECT * FROM wp_posts LEFT JOIN wp_postmeta ON (wp_posts.ID=wp_postmeta.post_id), wp_post2cat , wp_categories WHERE wp_posts.ID=wp_post2cat.post_id AND wp_posts.post_status='publish' AND wp_post2cat.category_id=wp_categories.cat_ID AND wp_categories.cat_name='technical' ORDER BY ID DESC");

  4. 3stripe
    Member
    Posted 8 years ago #

    Hey wow thank you so much :-)

    Worked first time!

  5. 3stripe
    Member
    Posted 8 years ago #

    Could you explain the difference in that code then... how does JOIN work?

  6. VaamYob
    Member
    Posted 8 years ago #

    SELECT * FROM tableA LEFT JOIN tableB ON (tableA.c1 = tableB.ac1) means:

    Give me EVERY row from tableA; and where tableA.c1 does not have a matching tableB.ac1, just slap a null value for tableB.ac1 in the result and call it a day.

  7. 3stripe
    Member
    Posted 8 years ago #

    Ok that makes sense, cheers for the info!

  8. 3stripe
    Member
    Posted 8 years ago #

    This is working great now for me, but I wonder is it possible to change the output result so that it lists the posts by date, with newest at the top?

    I'm guessing it would be "ORDER BY post_date DESC"??

    [update: yup!]

Topic Closed

This topic has been closed to new replies.

About this Topic