Jump to content

Newbie Looping Through Array


gum1982

Recommended Posts

Hi People

 

I have got the following code which querys the db

 

 $tsql = $wpdb->prepare( "SELECT sd.user_id
                                 FROM {$specialisms_data_table} sd
                                 WHERE sd.field_id = {$specialising_field_id} AND sd.value LIKE %s", $specialism);

      

      $data = $wpdb->get_results( $tsql );
      echo "<pre>";
      print_r($data);
      echo "</pre>";

 

The output for the  print_r($data);

 

Array

(

    [0] => stdClass Object

        (

            [user_id] => 42

        )

 

    [1] => stdClass Object

        (

            [user_id] => 46

        )

 

)

 

I then want to loop through these ids and then outputs some off the required db fields. So i am trying to do this with a foreach loop but its not returning me with anything.

 

<?php foreach( $data as $value ) { ?>
    <?php echo $value; ?>
<?php } ?>

 

I am not getting any results any help what am i doing wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/201626-newbie-looping-through-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.