trouble getting a field to show using a function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shots
Forum Newbie
Posts: 2
Joined: Sat Sep 26, 2009 2:35 am

trouble getting a field to show using a function

Post by shots »

I've got some image categories, and each one is represented by an image. I want the category name to appear above the image for each category. The code is only returning the number of the category, which is created by an array. I can't for the life of me figure out how to get it to just show the name of the category instead. Here's the code I'm using

Code: Select all

function eb_album_title($id) {
    $sql="SELECT album_title FROM eb_albums WHERE album_id=".$id;
    $query=mysql_query($sql);
    return mysql_result($query,0);
}
 
function eb_albums() {
    global $lang;
    $albums=eb_albums_array();
    if(count($albums)>0) {
        $output="\t\t<ul id=\"albums\">\r\n";
        foreach($albums as $album) $output.="\t\t\t<P>Category $album[0]<P><a href=\"photos.php?album=".$album[0]."\"><img src=\"photos/category/".$album[0].".jpg\" alt=\"".$album[1]."\" /></a><P>\r\n";
        $output.="\t\t</ul>\r\n";
    }
    else $output="";
    return $output;
}

The category name should show up right after where it says Category, right before $album[0] in the eb_albums() function. Could someone point me in the right direction, please!!!???
Thanks,
Scott
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: trouble getting a field to show using a function

Post by requinix »

Code: Select all

$albums=eb_albums_array();
I imagine you should look at what kind of array you get back and figure out how to get a title from it.
shots
Forum Newbie
Posts: 2
Joined: Sat Sep 26, 2009 2:35 am

Re: trouble getting a field to show using a function

Post by shots »

The array I get back is simply the number of the cateogry in question, i.e. (1), (2), (3), etc. I'm not experienced enough with PHP to know how to say "if 1, then output catetory Snakes". That's why I posted here, to get some help from the experts!
Thanks,
Scott
Post Reply