gum1982 Posted May 13, 2010 Share Posted May 13, 2010 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 More sharing options...
Psycho Posted May 13, 2010 Share Posted May 13, 2010 Your query is only extracting one field from the database: sd.user_id. If you want other data returned you need to modify your query to get it. Link to comment https://forums.phpfreaks.com/topic/201626-newbie-looping-through-array/#findComment-1057735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.