Page 1 of 1

trouble getting a field to show using a function

Posted: Sat Sep 26, 2009 2:41 am
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

Re: trouble getting a field to show using a function

Posted: Sat Sep 26, 2009 2:58 am
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.

Re: trouble getting a field to show using a function

Posted: Sat Sep 26, 2009 11:07 am
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