KevinM1 Posted January 10, 2007 Share Posted January 10, 2007 I'm trying to dynamically create an image's src attribute. I have the following echo statement:[code]<?phpecho "<img src='../images/store/{$tablename}_banner.jpg' alt='' /><a href='viewcart.php'><img src='../images/store/storefront_02.jpg' alt='View Cart' /></a>\n\n<div>";?>[/code]The problem is that $tablename is not inserted into the image's src attribute, leaving me with the script trying to display /images/store/_banner.jpg, which is definitely not what I want. Please help. Link to comment https://forums.phpfreaks.com/topic/33615-img-src-construction-problem/ Share on other sites More sharing options...
psychohagis Posted January 10, 2007 Share Posted January 10, 2007 can u put more of your script on here please Link to comment https://forums.phpfreaks.com/topic/33615-img-src-construction-problem/#findComment-157495 Share on other sites More sharing options...
mkosmosports Posted January 10, 2007 Share Posted January 10, 2007 Yeah, some more code would be helpful.Where is $tablename derived from? Link to comment https://forums.phpfreaks.com/topic/33615-img-src-construction-problem/#findComment-157496 Share on other sites More sharing options...
KevinM1 Posted January 10, 2007 Author Share Posted January 10, 2007 $tablename is simply created through a $_GET assignment:[code]<?php$tablename = $_GET['cat'];?>[/code]My full script is:[code]<?php#viewcat.php scriptsession_start();ob_start();include('../php_config/config.php');include('../dbconnect.php');include('../templates/sub_header.inc');if(isset($_GET['cat'])){ $tableName = $_GET['cat'];}else{ $_SESSION['ip'] = urlencode(serialize($ip)); $_SESSION['myCart'] = urlencode(serialize($myCart)); header("Location: http://www.thinkingmachinestore.com/storefront.php"); exit();}$query = "SELECT * FROM $tableName WHERE availability='y'";$result = mysql_query($query);echo "<div style='margin-left: auto; margin-right: auto; text-align: center;'><img src='../images/store/{$tablename}_banner.jpg' alt='' /><a href='viewcart.php'><img src='../images/store/storefront_02.jpg' alt='View Cart' /></a>\n<br /><br />\n";$count = 0;while($row = mysql_fetch_assoc($result)){ $id = $row["$tableName" . "_id"]; $pic = $row["pic_url"]; echo "<a href='viewitem.php?cat=$tableName&id=$id'><img src='$pic' alt='' /></a>"; $count++; if($count == 2){ echo "<br />\n"; $count = 0; }}echo "</div>";include('../templates/sub_footer.inc');?>[/code]EDIT: When I remove the brackets from $tablename, my src name actually shrinks to /images/store/.jpg, so that's not the problem. Link to comment https://forums.phpfreaks.com/topic/33615-img-src-construction-problem/#findComment-157512 Share on other sites More sharing options...
KevinM1 Posted January 11, 2007 Author Share Posted January 11, 2007 Hate to bump this up, but an answer would be nice. ;) Link to comment https://forums.phpfreaks.com/topic/33615-img-src-construction-problem/#findComment-158186 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 PHP is case sensitive.[code=php:0]$tablename = $_GET['cat'];[/code] Link to comment https://forums.phpfreaks.com/topic/33615-img-src-construction-problem/#findComment-158188 Share on other sites More sharing options...
KevinM1 Posted January 11, 2007 Author Share Posted January 11, 2007 Aha, I knew it had to be something dumb on my part!Thanks. :) Link to comment https://forums.phpfreaks.com/topic/33615-img-src-construction-problem/#findComment-158242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.