Jump to content

Taubulating data function problem


giraffemedia

Recommended Posts

I've got a bit of a problem echoing the results from a function that tabulates data from an array. I have one set up that populates a 2 column table and would like to change this to a 3 column layout using the function posted on the Rawstar 7 site http://www.rawstar7.co.uk/site/pro/php/general/tut_halves.html

 

Here is the function. The $issues array comes from a mysql query and works fine if I implode it then echo it, but it's not working with the function. Can anyone help please?

 

James

 

while($row=mysql_fetch_array($issues_result)) {

$issues[] = '<input name="issue_number[]" type="checkbox" value="' .$row['issue_number']. '" tabindex="11"  />Issue <strong>' .$row['issue_number'] . '</strong> ' . $row['issue_month'] . ' ' . $row['issue_year'] ;

} 

$data = $issues;

function table_04($data, $cols, $details="")
{
$sret = "<table ".$details.">\n";

$all = count($data);
$offset = ceil($all/$cols);

for($i=0; $i < $offset; $i++)
{
	$sret .= "<tr>";
	for($j=0; $j < $cols; $j++)
	{
		$sret .= "<td>".$data[($i+($j*$offset))]."</td>";
	}
	$sret .= "</tr>\n";
}
$sret .= "</table>\n";
return $sret;
}

print table_04($data, "border='1' width='100px'");

Link to comment
https://forums.phpfreaks.com/topic/120842-taubulating-data-function-problem/
Share on other sites

so do you just want horizontal repeat region with specified column amount?

 

here is how i do it, just a example from a page i have.

 

<table width="102" border="0">
  <tr>
<?php
  do { 
?>
  <td width="102" height="56" valign="top">
    
    Title: <?php echo $row_rsTour['title']; ?>
  
  </td>
  <?php
    $row_rsTour = mysql_fetch_assoc($rsTour);
    if (!isset($nested_rsTour)) {
      $nested_rsTour= 1;
    }
    if (isset($row_rsTour) && is_array($row_rsTour) && $nested_rsTour++ % 5==0) {
      echo "</tr><tr>";
    }
  } while ($row_rsTour);
?>
</tr>
</table>

 

the 5==0 there means it displays 5 columns. you can make it whatever. is this what your looking for?

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.