Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.