giraffemedia Posted August 22, 2008 Share Posted August 22, 2008 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'"); Quote Link to comment https://forums.phpfreaks.com/topic/120842-taubulating-data-function-problem/ Share on other sites More sharing options...
secoxxx Posted August 22, 2008 Share Posted August 22, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/120842-taubulating-data-function-problem/#findComment-622913 Share on other sites More sharing options...
giraffemedia Posted August 22, 2008 Author Share Posted August 22, 2008 Yes secoxxx. I want it to go 61 65 70 62 66 71 63 67 72 64 68 73 65 69 74 etc etc... Quote Link to comment https://forums.phpfreaks.com/topic/120842-taubulating-data-function-problem/#findComment-622916 Share on other sites More sharing options...
secoxxx Posted August 22, 2008 Share Posted August 22, 2008 look up at my last post. i edited it, but seeing as you want it to query down and not across now im not to sure, my script makes the data go from left to right. Ill check it out Quote Link to comment https://forums.phpfreaks.com/topic/120842-taubulating-data-function-problem/#findComment-622917 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.