Jump to content

[SOLVED] PHP: Displaying MySQL results with Smarty


FForce2195

Recommended Posts

Hello.  I started learning how to write PHP programs about 2 weeks ago.

 

I have a database table that consists of 16 fields.  I only want to display selection results under 3 fields for now.  And I'm using Smarty to display a table with alternating colors of rows.  Everything looks okay except...

 

As you see the screenshot below, each row is encircled by its own table.  I want to put all rows in one table.  For that end, how should I modify the code below?

 

 

<html>
<head>
<meta http-eqiv="Content-Type" content="text/html; charset=UTF-8">
<title>XXX</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="620" width="100%" border="1" cellspacing="0" cellpadding="0"class="title">
<tr bgcolor="#000066"><th width="50">Spam Post ID</th><th width="50">Date (GMT)</th><th width="520">Spam comments</th></tr>
{foreach item=spam from=$spam}
<table width="620" width="100%" border="1" cellspacing="0" cellpadding="0" class="font_control">
  <tr bgcolor="{cycle values="#E9E9E9,#9BB4EE"}">
    <td width="50" align="center">{$spam.comment_ID}</td>
    <td width="50">{$spam.comment_date_gmt}</td>
    <td width="520">{$spam.comment_content|chunk_split:95:"\n"}</td>
  </tr>
</table>
{/foreach}

</body>
</html>

 

 

Thanks a lot for your help.

 

Tom

 

[attachment deleted by admin]

This line needs to before you start the foreach loop

<table width="620" width="100%" border="1" cellspacing="0" cellpadding="0" class="font_control">

 

and this line needs to be after the foreach loop

 

</table>

Look at the line RIGHT after {foreach item=spam from=$spam}.  You have an opening table tag.  Remove it, and remove the closing </table> tag right before {/foreach}, and your problem should be fixed.

 

Yes, that works.  Muchas gracias.  Muchas gracias to Bendude14 as well. 

 

Some day, I'm going to be an expert PHP programmer who will be able to help both of you.  Maybe, one year from now...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.