2013-03-17 1 views
1

저는 데이터베이스에서 imagename을 얻기 위해 mysql 쿼리를 작성하고 있지만 올바른 방법으로 선택할 수는 없습니다. 내 웹 사이트의 회원 ID를 기반으로 imagename을 얻고 싶습니다. 나는 여러 번 시도했지만 여러 번 실패했습니다. 누구든지 나를 도울 수 있다면 .. 대단히 감사합니다. 난이 MySQL의 쿼리 할 경우ID를 기반으로 이미지 URL을 얻으려면 MySQL을 선택하십시오

는 :

resource(200) of type (mysql result) 

을 그리고 난이 쿼리하려고하는 경우 :

$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); 

를 내가 얻을

$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); 

을 나는이 다음 얻을 :

array(1) { ["banner"]=> string(19) "banner-animated.gif" } 

두 번째 괜찮습니다,하지만 그 유일한 imagename,하지만 난 이드를 참조하십시오.

+0

음이 적응, 당신은 당신의 문에 ID를 _selecting_되지 않습니다. – CBroe

답변

0
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>"; 

내 예 MYSQLI에, 귀하의 요구 사항

+0

답장을 보내 주셔서 감사합니다. Daryl,하지만 Smarty PHP 템플릿 엔진을 사용합니다. 내 tpl에 그것은 그렇게 :

+0

위의 쿼리를 수정하여 원하는 기준을 검색하십시오. 나는 Smarty에 대한 많은 경험이 없으므로 불행하게도 더 이상 당신을 도울 수 없습니다 –

+0

Lemil77s 예제를 사용해 보셨습니까? –

0

이 에코 ... -> 필요에 따라

$GetBannerImage['banner'] 

그것은 돌아갑니다 ... 는 "배너-animated.gif는"

그런 다음 템플릿에서 사용.

감사합니다.

@leo. 주어진

+0

새로운 PHP를 만들기 위해이 문제를 해결했습니다 : $ answer = mysql_query ("select banner FROM banner_images WHERE banner_id = '0'"); $ numrows = mysql_num_rows ($ answer); if ($ numrows == 0) { $ GetBannerImages = ""; } else { while ($ row = mysql_fetch_array ($ answer)) { $ i ++; $ GetBannerImage = $ row [ 'banner']; if ($ i! = $ numrows) { $ GetBannerImages. = $ GetBannerImage. ""; } else { $ GetBannerImages. = $ GetBannerImage; } } } 하지만 모두 도와 주셔서 감사합니다. –

관련 문제