Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple table rows dependant upon the number of records returned

Status
Not open for further replies.

Chucklez

Programmer
Jul 25, 2002
104
0
0
US
Im having a problem with my display not showing corectly. I query a MySQL DB, return a recordset (lets say 10 records), then do a for loop to cycle thru 10 times and create in essence 10 new table rows to display all my info. I know the "<#DOMINI_TEXT$d#>" is working correctly because if I change $d to 6, the 7th record from the recordset is displayed. But that is the only one to be displayed. Where am I going wrong in my template code?

Gathering the information
Code:
   $arrDOMINI_INFORMATION = mySQL_query("SELECT * FROM $tblDOMINI WHERE MAGE_ID = '$varMAGE_NUMBER'"); // or die(mysql_error());	
   $varDOMINI_COUNT=mysql_numrows($arrDOMINI_INFORMATION);
   mysql_close();
   $d=0;

for my template code:
Code:
<?
$template = <<< HTML

...blah blah blah...
...other stuff other stuff...

<table cellpadding = "0" cellspacing = "0" border = "0">
  <tr>
    <td>
      <img src="images/domini_top.jpg" border = "0" width = "432" height = "174">
    </td>
  </tr>
  <tr valign="top">
    <td class="renuntio" height="254">
<? for($d = 0; $d < $varDOMINI_COUNT; ++$d) { ?>
      <table width = "432">
        <tr>
	  <td class = "newsBold">
            <center>
	      <#DOMINI_TEXT$d#>
            </center>
          </td>
        </tr>
      </table>
<? } ?>
    </td>
  </tr>
  <tr>
    <td>
      <img src="images/domini_bottom.jpg" border="0" height = "130">
    </td>
  </tr>
</table>

...blah blah blah...
...other stuff other stuff...
HTML;
?>

And finally where I place the live info in the template:
Code:
while($d<$varDOMINI_COUNT){
   $varDOMINI_TEXT = mysql_result($arrDOMINI_INFORMATION,$d,"DOMINI_TEXT");
   $template = eregi_replace("<#DOMINI_TEXT$d#>", $varDOMINI_TEXT, $template);
   $d++;
}
 
I figured it out, I needed to bust out of the HTML code to get it to work:
Code:
<table cellpadding = "0" cellspacing = "0" border = "0">
  <tr>
    <td>
      <img src="images/domini_top.jpg" border = "0" width = "432" height = "174">
    </td>
  </tr>
  <tr valign="top">
    <td class="renuntio" height="254">
HTML;
for($d = 3; $d < $varDOMINI_COUNT; ++$d) {
$template .= <<< HTML
      <table width = "432">
        <tr>
          <td class = "newsBold">
            <center>
              <#DOMINI_TEXT$d#>
            </center>
          </td>
        </tr>
      </table>
HTML;
}
$template .= <<< HTML
    </td>
  </tr>
  <tr>
    <td>
      <img src="images/domini_bottom.jpg" border="0" height = "130">
    </td>
  </tr>
</table>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top