0

all

I am using this foreach loop

foreach ($entries as $entry)
{
    global $wpdb;
    //$pname = $wpdb->get_var("SELECT meta_value FROM wp_frm_item_metas WHERE (field_id=228 && item_id=$entry->id) OR (field_id=301 && item_id=$entry->id) OR (field_id=120 && item_id=$entry->id)");
    $pname1 = $wpdb->get_results("SELECT id FROM wp_frm_item_metas WHERE (field_id=(SELECT id FROM wp_frm_fields WHERE field_key ='$field_key') && item_id=$entry->id)");

    echo "<pre>";
    print_r($pname1);
    echo "</pre>";
}

And its result is

Array
(
    [0] => stdClass Object
        (
            [id] => 984
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1047
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1077
        )

)

I Want to marge it in single array. I tried this....

$genreArray=array();

foreach ($entries as $entry)
{
    global $wpdb;
    //$pname = $wpdb->get_var("SELECT meta_value FROM wp_frm_item_metas WHERE (field_id=228 && item_id=$entry->id) OR (field_id=301 && item_id=$entry->id) OR (field_id=120 && item_id=$entry->id)");
    $pname1 = $wpdb->get_results("SELECT id FROM wp_frm_item_metas WHERE (field_id=(SELECT id FROM wp_frm_fields WHERE field_key ='$field_key') && item_id=$entry->id)");

    $result = array_merge_recursive($genreArray, $pname1);         
}

But, its display me only last value of array.

3
  • What is $result and why do you merge into it instead of $genreArray? Commented Feb 15, 2012 at 9:07
  • Tell use more about what $wpdb is. Is it something from Wordpress? Is it a DB abstraction layer? Perhaps it has a method to return arrays instead of objects. Commented Feb 15, 2012 at 9:12
  • $wpdb is wordpress global variable Commented Feb 15, 2012 at 9:14

1 Answer 1

2
$genreArray = array_merge_recursive($genreArray, $pname1);
Sign up to request clarification or add additional context in comments.

1 Comment

Its work for me but, what i exact want is this loop function 5 times.now i am getting this Array ( [0] => stdClass Object ( [id] => 984 ) [1] => stdClass Object ( [id] => 1047 ) ) Array ( [0] => stdClass Object ( [id] => 1077 ) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.