Jump to content

Dymamic filename for image element


garry27

Recommended Posts

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>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.