Hi, I'm new to MySQL and I need to get the filenames of pictures stored in the wordpress database. I read up that you are supposed to use the $wpdb variable to access the database in WP. I have the gallery id and need to get a list of all the pictures/rows in the picture table by selecting those with the same id. Something like this: $result = $wpdb->query("SELECT * FROM wp_ngg_pictures WHERE galleryid=1"); Code (markup): then I want to display the pictures using a loop similar to: <table><tr> while ($myrow = mysql_fetch_array($result)) { echo "<td>".$myrow["filename"]."</td>"; } </tr></tabel> Code (markup): That code did not work properly, what am I doing wrong?
try this $result = $wpdb->get_results("SELECT * FROM wp_ngg_pictures WHERE galleryid=1"); this will return you as array as an object..
Thanks, I think that works but how do you access the results that are returned? and in the SQL query, how do you use a variable for galleryid - what is the correct syntax? galleryid=$idvariable does not work.