sanderphp Posted May 6, 2008 Share Posted May 6, 2008 I would like to print each result in a table style (like excel) rather than spacing it with -- between them like I am right now. I am not sure how to use and where to put <tr><td> in a statement like this. foreach($results as $r){ echo ('<li><a href="single.php?id='.$r['id'].'">'.$r['date'].'</a> -- '.$r['total_distance'].' -- '.$r['total_time'].' -- '.$r['ave_speed'].' <br><br>'); Link to comment https://forums.phpfreaks.com/topic/104310-solved-how-to-use-lttrgtlttdgt-in-an-echo-statement/ Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 Echo the <table> tags before and after the foreach loop, and echo the TR and TD tags as you see fit inside the foreach loop. Link to comment https://forums.phpfreaks.com/topic/104310-solved-how-to-use-lttrgtlttdgt-in-an-echo-statement/#findComment-534098 Share on other sites More sharing options...
Fadion Posted May 6, 2008 Share Posted May 6, 2008 Im sure u posted this once, as i replied to it. U shouldnt open new threads on the same problem. <?php echo '<table>'; foreach($results as $r){ echo '<tr>'; echo '<td>' . $r['id'] . '</td>'; echo '<td>' . $r['date'] . '</td>'; //all the other variables echo '</tr>'; } echo '</table>'; ?> As u may know, tr inserts a table row and td inserts a table cell. Guess thats how u wanted it. Link to comment https://forums.phpfreaks.com/topic/104310-solved-how-to-use-lttrgtlttdgt-in-an-echo-statement/#findComment-534101 Share on other sites More sharing options...
sanderphp Posted May 6, 2008 Author Share Posted May 6, 2008 That code works but it's just putting the data together. I am trying to show the gridlines. Would my style sheet keep the lines from showing up? if(count($results)){ //DISPLAY THE DATA echo '<table>'; foreach($results as $r){ echo '<tr>'; echo '<td>' . $r['id'] . '</td>'; echo '<td>' . $r['date'] . '</td>'; //all the other variables echo '</tr>'; } echo '</table>'; } else{ echo('Sorry - no results found'); } Link to comment https://forums.phpfreaks.com/topic/104310-solved-how-to-use-lttrgtlttdgt-in-an-echo-statement/#findComment-534103 Share on other sites More sharing options...
realjumper Posted May 6, 2008 Share Posted May 6, 2008 I'm not 100% sure what you mean by 'gridlines'.....but this css will show 1 pixel borders around your table cells <style type="text/css"> table, td { border-color: #000000; border-style: solid; } table { border-width: 0 0 1px 1px; border-spacing: 0; border-collapse: collapse; } td { margin: 0; padding: 4px; border-width: 1px 1px 0 0; } </style> Link to comment https://forums.phpfreaks.com/topic/104310-solved-how-to-use-lttrgtlttdgt-in-an-echo-statement/#findComment-534109 Share on other sites More sharing options...
Fadion Posted May 6, 2008 Share Posted May 6, 2008 Make a style that fits what ure aiming and assign its id or class to the table: table.grid{ border: 1px solid #000099; width: 500px; } tr.header{ background-color:#666666; color:white; } Link to comment https://forums.phpfreaks.com/topic/104310-solved-how-to-use-lttrgtlttdgt-in-an-echo-statement/#findComment-534110 Share on other sites More sharing options...
sanderphp Posted May 6, 2008 Author Share Posted May 6, 2008 Realjumper, I added your code to my script and that does exactly what I want. GuiltyGear, I assume your suggestion is to add it to my style.css and just call style.css? <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="style.css"/> Thanks everyone!!!! Link to comment https://forums.phpfreaks.com/topic/104310-solved-how-to-use-lttrgtlttdgt-in-an-echo-statement/#findComment-534118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.