Page 1 of 1

[SOLVED] Trouble displaying variable during FOR loop

Posted: Thu Feb 03, 2005 3:42 pm
by squatchimo

Code: Select all

<?php include('common.php');
$query = "SELECT * FROM store_items";
$result = mysql_query($query) or die(mysql_error());

$output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.smallfont &#123;
	font-family: "Bavaria Regular";
	font-size: 8px;
	color: #333333;
&#125;
-->
</style>
</head>
<body bgcolor="f2f1dc" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="smallfont">Test</td>
  </tr>
</table>
<table width="500" border="0" cellspacing="0" cellpadding="0">';
    $howmany = mysql_num_rows($result); 
    $rowmax = 3; 
    for($x = 0; $row = mysql_fetch_array($result); $x++) 
    &#123; 
        if($x % $rowmax == 0) 
            $output .= "<tr>\n"; 
        $item_title = $row&#1111;"item_title"];

        $output .= '<td align="center"><table width="135" height="143" border="0" cellpadding="0" cellspacing="0">
      <tr valign="top">
        <td height="18" colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="/test/images/top.jpg">
          <tr>
            <td width="12">&nbsp;</td>
            <td valign="top" class="smallfont">$item_title</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td width="10"><img src="/test/images/side.jpg" width="10" height="125"></td>
        <td><img src="/test/images/image.jpg" width="125" height="125"></td>
      </tr>
    </table></td>';
	
if($x % $rowmax == $rowmax - 1) 
$output .= "\r</tr>\n\n";
&#125;
$output .= '</table>
</body>
</html>';
echo $output;
?>
In the above code, I need $item_title to display a value for each cell generated with the FOR loop. However, when the code runs, each cell is generated properly but each one says "$item_title". How do I get PHP to recognize this variable and plug the correct value in?

Thanks for the help!

Posted: Thu Feb 03, 2005 4:45 pm
by feyd
$item_title appears inside a single quoted string. PHP will not parse any variables inside such a string.

Posted: Thu Feb 03, 2005 5:06 pm
by squatchimo
So simple!

Thank you VERY much for helping me Feyd!