mySql custom select and display
I am trying to get custom data from my wordpress database,开发者_开发问答 but my knowledge in sql ist that good. Could some one help me?
Please look at my example.
I am trying to echo out image names (filename) from table (wp_ngg_pictures) that have galleryid = 2
So in this example I would get the list of :
- bildes-140.jpg
- bildes-127.jpg
- bildes-133.jpg
- bildes-152.jpg
- And so on....
Assuming your using PHP all you would do is connect to your database and then do something like this
$result = mysql_query("SELECT * FROM wp_ngg_pictures WHERE galleryid = 2")or die (mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo $row['filename'];
}
If you wanted more specific results it would be a little different. Fixed the errors.. sorry bout that, still learning myself.
This should Loop though all galleries with id of 2 and echo out the id and file name.
$GetAlbum=2;
$sql = "SELECT * FROM YOURDATABASE.wp_ngg_pictures WHERE galleryid LIKE '%".$GetAlbum."%'";
$result=mysql_query($sql) or die ('Error! Could not get gallery Databse.');
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$gallery=mysql_result($result,$i,"galleryid");
$galleryImg=mysql_result($result,$i,"filename");
echo 'ID '.$gallery.' File '.$galleryImg.'';
}
SELECT filename from wp_ngg_pictures WHERE galleryid = 2
精彩评论