I am just creating a mysql query to get imagename from database, but i can't select on the right way. I want to get imagename based on ID of member at my website. I did try many times, but i failed many times. If anyone can help me.. Thank you very much then.
If i do this mysql query:
$GetBannerImageSql = $database->database_query("SELECT banner FROM banner_images WHERE banner_id='".$owner->user_info['user_id']."'");
$smarty->assign('bannerexists', $bannerexists);
$smarty->assign('GetBannerImage', $GetBannerImage);
I get:
resource(200) of type (mysql result)
And if i try this query:
$GetBannerImageSql = $database->database_query("SELECT banner FROM banner_images WHERE banner_id='".$owner->user_info['user_id']."'");
$GetBannerImage = $database->database_fetch_assoc($GetBannerImageSql);
var_dump($GetBannerImage);
$smarty->assign('bannerexists', $bannerexists);
$smarty->assign('GetBannerImage', $GetBannerImage);
I get this then:
array(1) { ["banner"]=> string(19) "banner-animated.gif" }
Second is fine, but its only imagename, but i dont see id.
echo this... ->
$GetBannerImage['banner']
It will return ... "banner-animated.gif"
Then use it in your template as needed.
Thanks!
@leo.
CREATE TABLE IF NOT EXISTS `PicturePath` (
`ID` int(255) NOT NULL AUTO_INCREMENT,
`Path` varchar(255) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;
--
INSERT INTO `PicturePath` (`ID`, `Path`) VALUES
(1, 'img/picture.png');
//End DB
// Start script
$PictureID = $_GET['ID']; // example, user is navigating to http://www.mysite.com/Picture.php?ID=1
$Get_Picture = $Conn->prepare("SELECT PicturePath FROM pictures WHERE ID=?");
$Get_Picture->bind_param('i', $PictureID);
$Get_Picture->execute();
$Get_Picture->bind_result($Path);
$Get_Picture->close();
echo "<img src='$Path'></img>";
My example given is in MYSQLI, adapt this to your requirements
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.