Jump to content

[SOLVED] How to use <tr><td> in an echo statement


sanderphp

Recommended Posts

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>');

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.

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');
}

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>


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!!!!

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.