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.

query_posts with an array

Discussion in 'PHP' started by aaron_nimocks, Dec 20, 2008.

Thread Status:
Not open for further replies.
  1. #1
    My head is bleeding from beating it against the wall.

    Trying to show all the posts that dont have reviews yet on this page

    http://www.reviewshut.com/category/web-hosting (which is category ID 3)

    Now the array you see on the top is all the post ID's I want displayed.

    Only problem is I cant get the format right with query_posts

    if (is_category('3'))
    {
        $notreviewed = unrated_count();
        echo implode(",", $notreviewed);
        query_posts('p=.implode(',', $notreviewed)');
    }
    PHP:
    Thats what I have now but I tried a ton of different stuff. Any ideas??

    The code works if I do

    
        query_posts('p=1,2,3,4,5,6');
    
    PHP:
    But not if I put that array in there. Im sure Im just not formatting the command correctly.

    Thanks!
     
    aaron_nimocks, Dec 20, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    $notreviewed = unrated_count();
    query_posts( 'p=' . implode(',', is_array($notreviewed) ? $notreviewed : array((string)$notreviewed)) );
    PHP:
     
    Danltn, Dec 20, 2008 IP
  3. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #3
    tried it and it didnt find any posts

     
    aaron_nimocks, Dec 20, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Your problem then I guess, it's running query_posts('p=1,2,3,4,5,6'); where 1,2,3,4,5,6 are (presumably) the ids of the posts - depends on what unrated_count() returns.

    Dan.
     
    Danltn, Dec 20, 2008 IP
  5. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #5
    I checked the array that it spits out on that page and its the right IDs and they do exist.
     
    aaron_nimocks, Dec 20, 2008 IP
  6. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Feel free to test it, it does what it says on the tin.

    $notreviewed = range(1, 6, 1);
    
    echo( 'p=' . implode(',', is_array($notreviewed) ? $notreviewed : array((string)$notreviewed)) );
    PHP:
    Returns:
    p=1,2,3,4,5,6
    Code (markup):
    - Which would then be parsed to the function. Assuming query_posts works correctly.
     
    Danltn, Dec 20, 2008 IP
  7. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #7
    Apparently that function only handles one post ID. :(
     
    aaron_nimocks, Dec 20, 2008 IP
Thread Status:
Not open for further replies.