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 Link to comment https://forums.phpfreaks.com/topic/49577-creating-a-function-for-image-fetching/ Share on other sites More sharing options...
illuz1on Posted May 2, 2007 Author Share Posted May 2, 2007 anyone?? Link to comment https://forums.phpfreaks.com/topic/49577-creating-a-function-for-image-fetching/#findComment-243373 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]; } Link to comment https://forums.phpfreaks.com/topic/49577-creating-a-function-for-image-fetching/#findComment-243379 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? Link to comment https://forums.phpfreaks.com/topic/49577-creating-a-function-for-image-fetching/#findComment-243458 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]; } Link to comment https://forums.phpfreaks.com/topic/49577-creating-a-function-for-image-fetching/#findComment-243464 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 Link to comment https://forums.phpfreaks.com/topic/49577-creating-a-function-for-image-fetching/#findComment-243480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.