illuz1on Posted May 2, 2007 Share Posted May 2, 2007 Hey ive just started storing images in a mysql database, but now I want to try and make a function that gets the image out the DB by the TITLE and prints it - like <? printimage(this.would.be.image.title); ?> How would I go about this?? This is my table structure: create table pics ( pid int primary key not null auto_increment, title text, imgdata longblob) Thanks alot Quote Link to comment Share on other sites More sharing options...
illuz1on Posted May 2, 2007 Author Share Posted May 2, 2007 anyone?? Quote Link to comment Share on other sites More sharing options...
taith Posted May 2, 2007 Share Posted May 2, 2007 you can do it that way... but i always prefer using id's for my indexes... doing them by name can be VERY tempermental... an example of one of my superfunctions... indexing pictures by `id`... first time its run, grabs all the information, puts it into the array, every next time, it just pulls from the array, only accesses database once $allpictures=array(); funcion get_pictures($id){ global $allpictures; if(!is_numeric($id)) return; if(!empty($allpictures[$id])) return $allpictures[id]; $query=mysql_query("SELECT * FROM `pictures`"); while($row=mysql_fetch_assoc($query)){ $allpictures[$row[id]]=$row[url]; } return $allpictures[$id]; } Quote Link to comment Share on other sites More sharing options...
illuz1on Posted May 2, 2007 Author Share Posted May 2, 2007 awesome yea I think thats what im looking for, but how would I adapt that to get from the title in db? Quote Link to comment Share on other sites More sharing options...
taith Posted May 2, 2007 Share Posted May 2, 2007 if ya say so... might cause you some more problems in the long run... but... your choice :-) $allpictures=array(); function get_picture($title){ global $allpictures; if(!empty($allpictures[$title])) return $allpictures[$title]; $query=mysql_query("SELECT * FROM `pictures`"); while($row=mysql_fetch_assoc($query)){ $allpictures[$row[title]]=$row[url]; } return $allpictures[$title]; } Quote Link to comment Share on other sites More sharing options...
illuz1on Posted May 2, 2007 Author Share Posted May 2, 2007 great thanks alot, will keep in mind to move to ID if i encounter problems Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.