garry27 Posted June 27, 2011 Share Posted June 27, 2011 Why does my file name show up blank when I store it inside an image element? <td><img src="images/blog <?php echo $row_Recordset1['filename']; ?> "/> </td> Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/ Share on other sites More sharing options...
MasterACE14 Posted June 27, 2011 Share Posted June 27, 2011 try: <td><img src="images/blog/<?php echo $row_Recordset1['filename']; ?>"/> </td> Maybe missing the forward slash? and you've got a space in there. Also check $row_Recordset1['filename'] exists. Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235461 Share on other sites More sharing options...
fugix Posted June 27, 2011 Share Posted June 27, 2011 what are the contents of your $row_Recordset1['filename'] Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235464 Share on other sites More sharing options...
garry27 Posted June 27, 2011 Author Share Posted June 27, 2011 I've removed the spaces and added the forward slash but the source code still missing the php output which works without the image tag. it should read b1.jpg. this adds the php output: <td><?php echo $row_Recordset1['filename'];?> </td> this doesn't: <td><img src="images/blog/<?php echo $row_Recordset1['filename'];?>"/> </td> Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235468 Share on other sites More sharing options...
PFMaBiSmAd Posted June 27, 2011 Share Posted June 27, 2011 Have you examined the 'view source' of the page in your browser? Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235470 Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2011 Share Posted June 27, 2011 Does the file in question have a .php file extension? Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235472 Share on other sites More sharing options...
garry27 Posted June 27, 2011 Author Share Posted June 27, 2011 No, it's just a .jpg extension. Here's the source code when it works: <td>bid1.jpg </td> I can't understand it as I got this working on a similar implementation before. I'm using Dreamweaver to build a Master Detail Page and like I said it worked when I tried it last time. Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235477 Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2011 Share Posted June 27, 2011 No, I mean the one from which you've posted the above lines of code. Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235478 Share on other sites More sharing options...
garry27 Posted June 27, 2011 Author Share Posted June 27, 2011 No, I mean the one from which you've posted the above lines of code. I'm confused No, I mean the one from which you've posted the above lines of code. I don't understand Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235482 Share on other sites More sharing options...
garry27 Posted June 27, 2011 Author Share Posted June 27, 2011 Does the file in question have a .php file extension? Yes, it's a php file. Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235484 Share on other sites More sharing options...
fugix Posted June 27, 2011 Share Posted June 27, 2011 No, I mean the one from which you've posted the above lines of code. I'm confused No, I mean the one from which you've posted the above lines of code. I don't understand i believe Pikachu means the actual file that contains <td><img src="images/blog/<?php echo $row_Recordset1['filename'];?>"/> </td> Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235485 Share on other sites More sharing options...
PFMaBiSmAd Posted June 27, 2011 Share Posted June 27, 2011 And the source code in the browser for when it doesn't work is???... Posting the source for something that works, doesn't really help with finding out why something doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235486 Share on other sites More sharing options...
garry27 Posted June 27, 2011 Author Share Posted June 27, 2011 <td><img src="images/blog/<?php echo $row_Recordset1['filename'];?>"/> </td> = <td><img src="images/blog/"\> </td> Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235496 Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2011 Share Posted June 27, 2011 Obviously, the variable has no value, or contains an empty string. There could be many reasons for that; failed database query, value being overwritten, etc. You'll need to post all of the relevant code, from the db connection and query through the part that includes the line that isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235498 Share on other sites More sharing options...
garry27 Posted June 27, 2011 Author Share Posted June 27, 2011 ok, here's the code for the whole page lol <?php require_once('Connections/myDBconn.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Recordset1 = 10; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_myDBconn, $myDBconn); $query_Recordset1 = "SELECT b.bid, b.`date`, b.title, mc.content, u.fname, u.lname, i.filename, t.teaser FROM (Blog b, MainContent mc, `User` u, Teaser t) left join Image as i on i.iid = b.iid WHERE mc.mcid = b.mcid AND u.`uid` = b.`uid` AND b.tid = t.tid ORDER BY `date` ASC #SELECT b.`date`, b.title, mc.content, u.fname, u.lname, b.bid, i.filename #FROM (Blog b, MainContent mc, `User` u) left join Image as i on i.iid = b.iid #WHERE mc.mcid = b.mcid AND u.`uid` = b.`uid` #ORDER BY `date` ASC"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $myDBconn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); $query_Recordset1 = "SELECT b.bid, b.`date`, b.title, mc.content, u.fname, u.lname, i.filename, t.teaser FROM (Blog b, MainContent mc, `User` u, Teaser t) left join Image as i on i.iid = b.iid WHERE mc.mcid = b.mcid AND u.`uid` = b.`uid` AND b.tid = t.tid ORDER BY `date` ASC #SELECT b.`date`, b.title, mc.content, u.fname, u.lname, b.bid, i.filename #FROM (Blog b, MainContent mc, `User` u) left join Image as i on i.iid = b.iid #WHERE mc.mcid = b.mcid AND u.`uid` = b.`uid` #ORDER BY `date` ASC"; $Recordset1 = mysql_query($query_Recordset1, $myDBconn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table border="1" align="center"> <tr> <td>bid</td> <td>date</td> <td>title</td> <td>content</td> <td>fname</td> <td>lname</td> <td>filename</td> <td>teaser</td> </tr> <?php do { ?> <tr> <td><a href="t2.php?recordID=<?php echo $row_Recordset1['bid']; ?>"> <?php echo $row_Recordset1['bid']; ?> </a></td> <td><?php echo $row_Recordset1['date']; ?> </td> <td><?php echo $row_Recordset1['title']; ?> </td> <td><?php echo $row_Recordset1['content']; ?> </td> <td><?php echo $row_Recordset1['fname']; ?> </td> <td><?php echo $row_Recordset1['lname']; ?> </td> <td><img src="images/blog/<?php echo $row_Recordset1['filename'];?>"/> </td> <td><?php echo $row_Recordset1['teaser']; ?> </td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <br /> <table border="0"> <tr> <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a> <?php } // Show if not first page ?></td> <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a> <?php } // Show if not first page ?></td> <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a> <?php } // Show if not last page ?></td> <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a> <?php } // Show if not last page ?></td> </tr> </table> Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?> </body> </html> <?php mysql_free_result($Recordset1); ?> There's nothing wrong with the database connection as all the table cells populate all right it's just this one awkward one I can't fathom. Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235505 Share on other sites More sharing options...
garry27 Posted June 27, 2011 Author Share Posted June 27, 2011 I've rebuilt the page in DW and it's sorted itself out Thanks for all your help . Quote Link to comment https://forums.phpfreaks.com/topic/240528-dymamic-filename-for-image-element/#findComment-1235528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.