Re: [SMARTY] return img tag

From: Date: Mon, 16 Dec 2002 06:35:52 +0000
Subject: Re: [SMARTY] return img tag
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6816@lists.php.net to get a copy of this message
It looks like the image itself comes from the db, right? There are several ways to do it. First of all, put the <img src> tag in the template, don't pass it as text. So here's one way: fetch_page.php --------------- $query = "SELECT imid,width,height,border,alt FROM c_image WHERE imid='$imid'"; $res = mysql_query($query); while ($data = mysql_fetch_array ($res)) { $smarty->assign($data); } $smarty->display('index.tpl'); index.tpl ---------- {if is_array($data)} <img src="fetch_image.php?imid={$data.imid}" height="{$data.height}"
          width="{$data.width}" border="{$data.border}" alt="{$data.alt}">
{/if} fetch_image.php ---------------- header('Content-Type: image/gif'); $query = "SELECT file FROM c_image WHERE imid='$imid'"; $res = mysql_query($query); while ($data = mysql_fetch_array ($res)) { echo $data['file']; } Another option is to write the image to disk and supply the filepath in the src attribute. Then there is only one db query. Monte Peter Pieczora wrote:
Hi, I am trying to display images which attributes are stored in db. Here is what I've done so far: index.php //---------- $query = "SELECT * FROM c_image WHERE imid='$imid'"; $res = mysql_query($query); while ($data = mysql_fetch_array ($res)) {
       $imid .= $data[imid];
       $basefile .= $data[file];
       $width .= $data[width];
       $height .= $data[height];
       $border .= $data[border];
$alt .= $data[alt]; } $smarty->assign("file", "$file"); $smarty->assign("width", "$width"); $smarty->assign("height", "$height"); $smarty->assign("border", "$border"); $smarty->assign("alt", "$alt"); $IMAGE="<IMG SRC=\"$file\" WIDTH=\"$width\" HEIGHT=\"$height\" BORDER=\"$border\" ALT=\"$alt\">"; $smarty->assign("IMAGE", "$IMAGE"); //-------- page.tpl {$IMAGE} ------------ So when I enter ?page&imid=x on URL bar image gets displayed. What I'm trying to come up with is how to pass variable {$IMAGE} which would allow me to display image based on $imid, from the template?


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