Re: [SMARTY] return img tag

From: Date: Mon, 16 Dec 2002 06:37:44 +0000
Subject: Re: [SMARTY] return img tag
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6815@lists.php.net to get a copy of this message
Hello Peter, I'm confused by the .= tags? why not make this cleaner .. $query = "SELECT * FROM c_image WHERE imid='$imid'"; $res = mysql_query($query); while ($data = mysql_fetch_array ($res)) { $data_array = array('imid' => $data[imid], 'file' => $data[file], 'width' => $data[width], 'height' => $data[height], 'border' => $data[border], 'alt' => $data[alt]); } $smarty->assign('data_array', $data_array); then call it on the .tpl page: with show image: <img src="{$data_array.file}"> Monday, December 16, 2002, 2:14:25 AM, you wrote: PP> Hi, PP> I am trying to display images which attributes are stored in db. PP> Here is what I've done so far: PP> index.php PP> //---------- PP> $query = "SELECT * FROM c_image WHERE imid='$imid'"; PP> $res = mysql_query($query); PP> while ($data = mysql_fetch_array ($res)) PP> { PP> $imid .= $data[imid]; PP> $basefile .= $data[file]; PP> $width .= $data[width]; PP> $height .= $data[height]; PP> $border .= $data[border]; PP> $alt .= $data[alt]; PP> } $smarty->>assign("file", "$file"); $smarty->>assign("width", "$width"); $smarty->>assign("height", "$height"); $smarty->>assign("border", "$border"); $smarty->>assign("alt", "$alt"); PP> $IMAGE="<IMG SRC=\"$file\" WIDTH=\"$width\" PP> HEIGHT=\"$height\" PP> BORDER=\"$border\" ALT=\"$alt\">"; $smarty->>assign("IMAGE", "$IMAGE"); PP> //-------- PP> page.tpl PP> {$IMAGE} PP> ------------ PP> So when I enter ?page&imid=x on URL bar image gets displayed. PP> What I'm trying to come up with is how to pass variable {$IMAGE} which would PP> allow me to display image based on $imid, from the template? PP> -- PP> Smarty General Mailing List (http://smarty.php.net/) PP> To unsubscribe, visit: http://www.php.net/unsub.php -- Best regards, guido mailto:sguido@rogers.com

« previous php.smarty.general (#6815) next »