FForce2195 Posted October 11, 2008 Share Posted October 11, 2008 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] Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/ Share on other sites More sharing options...
DarkWater Posted October 11, 2008 Share Posted October 11, 2008 Read your code. You clearly have a table tag right in the {foreach}. Just take it out. Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/#findComment-662402 Share on other sites More sharing options...
FForce2195 Posted October 11, 2008 Author Share Posted October 11, 2008 Hello. What do you exactly mean, por favor? Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/#findComment-662452 Share on other sites More sharing options...
DarkWater Posted October 11, 2008 Share Posted October 11, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/#findComment-662455 Share on other sites More sharing options...
Bendude14 Posted October 11, 2008 Share Posted October 11, 2008 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> Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/#findComment-662456 Share on other sites More sharing options...
DarkWater Posted October 11, 2008 Share Posted October 11, 2008 No, he already has those lines before the foreach. He has them REPEATED inside the foreach. Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/#findComment-662457 Share on other sites More sharing options...
Bendude14 Posted October 11, 2008 Share Posted October 11, 2008 yes your right but i thought that maybe since each table has a different class that the nested tables was to do with his page layout... Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/#findComment-662458 Share on other sites More sharing options...
FForce2195 Posted October 11, 2008 Author Share Posted October 11, 2008 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... Link to comment https://forums.phpfreaks.com/topic/127930-solved-php-displaying-mysql-results-with-smarty/#findComment-662463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.