Producing a table from a loop with one array - php

I'm attempting to create a table using a loop. The number of columns is what matters, it should be 6-7, while the number of rows is irrelevant.
The problem here is that I need to create this from one array only, which has a set of image names which I need to display through the table.
This is the PHP:
if ($mode == 'skins')
{
$player_gender = ($player_data['playerGender'] == true) ? 'male' : 'female';
$skins_array = $samp->skin('small', false, $player_gender);
$index_counter = 0;
foreach ($skins_array as $skin_img)
{
$template->assign_block_vars('skinrow', array(
'IMAGE_PATH' => $root_path . $config['skins_path'] . '/Skin_' . $skin_img . '.png',
));
}
}
And this is the HTML:
<div class="container">
<table>
<!-- BEGIN skinrow -->
<tr>
<td><img src="{skinrow.IMAGE_PATH}" /></td>
</tr>
<!-- END skinrow -->
</table>
</div>
The template engine used in this case is from phpBB.
If I include the <tr> in the loop in the HTML, I get my results all going down (vertical) in one column and when I exclude the <tr> from the loop, the results all go aside in one row (horizontal).
So, I basically care for the number of columns only, I want those to be limited to 6-7.
I'm failing to see the logic on achieving this. Any help would be appreicated.
Here is an example array with the data I'm using: http://pastebin.com/uDMeBJw6
If the template engine is causing you trouble to understand the code, please let me know and I'll try to convert it to a pure PHP example.

MY phpBB skills are non-existant, but maybe this will do the trick:
Template:
<div class="container">
<table>
<tr>
<!-- BEGIN skinrow -->
{skinrow.NEW_TR} <!-- **EDITED** -->
<td><img src="{skinrow.IMAGE_PATH}" /> </td>
<!-- END skinrow -->
</tr>
</table>
</div>
PHP (loop only):
$counter = 0;
foreach ($skins_array as $skin_img)
{
$new_tr = ($counter && ($counter % 7 === 0)) ? '</tr><tr>' : ''; // **EDITED**
$template->assign_block_vars('skinrow', array(
'NEW_TR' => $new_tr,
'IMAGE_PATH' => $root_path . $config['skins_path'] . '/Skin_' . $skin_img . '.png',
));
}
Code is untested, this is just an idea.
... and it's probably cleaner to do for instead of dancing with foreach and $counter :)

Related

Dynamically add page-breaks to html with variable amount of sections of variable sizes

I'm trying to solve this current problem which I could use some help with:
From the database using php, the page must load an X number of sections, every section has some content on top, a table and some content on the bottom, the table can have 0 to any number of rows, depending on what was previously in the database.
Aside from the table the rest of the content doesn't vary in size.
I cannot know beforehand what will be the size of each section because of the table, and there is usually at least 30 sections.
This page must be print friendly, and aside from the page-breaks everything is already working.
I need to find a way to dynamically add page-breaks to fit the sections into the page without cutting them between pages.
The code is about 400 lines so it wouldn't be practical to post it here, but the section structure is something like this:
<section class="row">
<section>
<section class="col-md-2"></section>
<section class="col-md-8 printcenter">
<p class="docenteheader" >
<span class="tabspaceright">NAME: <strong>name</strong></span>
<span class="tabspaceleft">ID: <strong>number</strong></span>
</p>
<table>
  <tr>
    <th><strong>1:</strong></th>
<th><strong>2:</strong></th>
<th><strong>3:</strong></th>
<th><strong>4:</strong></th>
  </tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
<p><strong>Something1:</strong> Something</p>
<p>
<span><strong>Something2: number</strong></span>
<span ><strong>Something3: number</strong></span>
</p>
<section class="rel_endline"></section>
</section>
<section class="col-md-2"></section>
</section>
</section>
I removed the css classes and original names and PHP code to facilitate viewing
Here is sample PHP code, let me know if anything is unclear. I tried to use self-explaining variable names.
<?php
$PAGEBREAK_LENGTH = 1000; // Add a page break every 1000 characters.
$lengthTracker = '';
while ($row = odbc_fetch_array($res)){
$lengthTracker .= $row['article'];
$lengthSize = strlen($lengthTracker);
if ($lengthSize > $PAGEBREAK_LENGTH) {
echo '<div class="page-break">This is a page break</div>';
$lengthTracker = ''; // Reset length tracker since we just added a break
}
echo '<div class="article">';
echo $row['article'];
echo '</div>';
}
?>
If you include the if ($lengthSize > $PAGEBREAK_LENGTH) before echoing the article, you will tend to include page-breaks "more often." If you include the if statement after the article is echod, you will have page-breaks less often (so you'd have potentially bigger blocks of text).
Experiment with both ways to see which style you prefer, since you (presumably) can't include page breaks mid-article.
I found out that my problem was caused not by the faulty page breaks, but I had negative margins in an element, that messed the entire way page breaks work, by removing that, it worked normally.

Display multiple PHP query results in HTML

So have the following while loop which will output all the results for a SQL query carried out in PHP:
while ($row = mysqli_fetch_array($result))
{
$restaurant_name = $row['restaurant_name'];
$cusine = $row['cusine'];
$wait_time = $row['wait_time'];
$output = "Resturant Name: $restaurant_name <br /> Cusine: $cusine <br /> Average Wait Time: $wait_time";
echo "$output";
}
You can assume that $result will contain the table which I am reading on row at a time. The above code is working just fine but when I try to display the information in HTML (so that it actually looks nice) I run into a problem
If I do the following:
<html>
<section id="main" class="container 75%">
<header>
<h2>Here Are Some Places You'd Like To Eat</h2>
</header>
<div class="box">
<?php echo $output; ?>
</div>
</section>
</html>
It will only display the very last resort. I know that this happening because $output can only hold one string at a time, but I don't know any other way to display the information on the HTML. I though of possibly using an array to store all the strings, but the documentation doesn't show me how to set-up a dynamic array.
Does anyone here know how to display all the results of the search query in an HTML page?
You can do combine both php and html code like this:
<header>
<h2>Here Are Some Places You'd Like To Eat</h2>
</header>
<?php
while ($row = mysqli_fetch_array($result)) :
$restaurant_name = $row['restaurant_name'];
$cusine = $row['cusine'];
$wait_time = $row['wait_time'];
$output = "Resturant Name: $restaurant_name <br /> Cusine: $cusine <br /> Average Wait Time: $wait_time";
echo "<div class=\"box\">$output</div>";
endwhile;
?>
This way you don't have to use an array to display the result.
<header>
<h2>Here Are Some Places You'd Like To Eat</h2>
</header>
<div class="box">
<?php
while ($row = mysqli_fetch_array($result)) {
$row = mysqli_fetch_array($result);
echo 'Restaurant name: '.$row['restaurant_name'];
echo 'Cusine: '.$row['cusine'];
// ...and so on
}
?>
</div>
You can have the loop produce the HTML inside your div with a table. I am not sure what your CSS is like for your box class, but this will certainly make it look better while printing out all of your results.
<header>
<h2>Here Are Some Places You'd Like To Eat</h2>
</header>
<div class="box">
<table>
<tr>
<td>Restaurant</td>
<td>Cusine</td>
<td>Wait Time</td>
</tr>
while ($row = mysqli_fetch_array($result))
{
$restaurant_name = $row['restaurant_name'];
$cusine = $row['cusine'];
$wait_time = $row['wait_time'];
echo "<tr><td>". $restaurant_name . "</td><td>" . $cusine . "</td><td>" . $wait_time . "</td></tr>";
}
</table>
</div>
You are overwriting your $output variable every loop, and then trying to echo $output later; it will only contain the data from the last iteration.
Instead, make $output an array containing your data and then loop over it for display purposes:
$output=array();
while ($row = mysqli_fetch_array($result)) :
$output[]=$row;
endwhile
Then you can loop over the $output array to build an output for each restaurant:
foreach($output as $value):
$returnDetails='<div class="box">';
$returnDetails.='Resturant Name: '.$output['restaurant_name'].'<br />';
// etc. for all details
$returnDetails.='</div>';
echo $returnDetails;
endforeach;
Added benefit of this way: you have access to the $output array if you ever wanted to access a single row outside the context of the loop

ForLoop echo placed in wrong area

<div class="row">
<div class="col-md-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Call Dialog</h3>
</div>
<!-- /.box-header -->
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tbody>
<tr>
<th>#</th>
<th>Callers</th>
<th>Expiration</th>
</tr>
<?php
$calls = array();
for ($i = 0; $i < 10; $i++) {
$template = "
<tr>
<td>". $i ."</td>
</tr>
";
echo $template;
}
?>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
</div>
</div>
So the above code produces the following output:
Whenever I edit the code to add $i + 1 so that the end output is going to be a 10 what happens is the code breaks and the output is given:
This is the very first time I've ever encountered this problem. If you could figure out what I did wrong or somehow what is wrong with either my html, way of printing, etc. please do let me know. If you have any questions regarding the problem or is confused about something I'll do my best to clarify.
The error happens because you are summing the concatenation of 1 and whatever is after.
Very shortly, this is what you are doing:
echo 'a string' . $i + 1 . 'another string';
This will be the same as:
echo 0 + 1;
(Strings that don't start with a number will automatically be converted to 0. All other strings will be truncated to a number. '9a' will be converted to 9 before summing it while 'a9' will be 0)
How to solve this:
Use parenthesis:
Surround the operation in parenthesys will avoid it being concatenated.
A basic example:
echo 'Your string has ' . ($length + 1) . ' characters';
Use comas instead of concatenation:
This will avoid any problems and will very slightly speed your code.
This is a known micro-optimization.
Using the basic example:
echo 'Your string has ', $length + 1, ' characters';
Use whichever solution works best for you.
Please separate php and html. It's easy and will save a lot of time for you. It's working fine
<?php
$calls = array();
for ($i = 0; $i < 10; $i++) {
?>
<tr>
<td><?=$i+1 ?></td>
</tr>
<?php
}
?>

Convert a parse ini to array / objects

I'm using a program I made to scrape a file for text and parse the information into a ini file. I asked a question here earlier asking about parse_ini_file and why I could not use the indexes and someone gave me a way to loop through using this.
$ini_array = parse_ini_file("myfile.ini", true
foreach($ini_array as $key=>$value)
I then echo out the result echo ($value['Username']) . " "; and store it into the table. I have the table functioning link here, http://liveviewtest.byethost7.com/index.php but the plugin I'm using is not functioning as intended. The sorting does not work, and I'm wondering is it because the data type? http://www.datatables.net/manual/data tells you that the accepted data types are arrays, objects, and instances. My question is what would be the best way for me to convert this into one of these data types? I'm new to php / html so sorry if this is basic.
Php File http://pastebin.com/VRUHLdMQ
Ini File http://pastebin.com/yZsg16qA
Your table is being generated so PHP & Ini file are fine but HTML code you are generating is incorrect so either DataTable plugin or jQuery DOM parser is confused.
Please fix it and it should work fine.
Put jquery+datatables js/css into <head> section.
You use multiple <tbody> and you put </tr> after </tbody>
So basically you shoud put echo "</tbody>"; outside loop so
echo "<tbody>"; // <<< HERE
foreach ($ini_array as $key => $value) {
echo "<tr>";
for ($i = 0; $i < 12; $i++) {
echo "<td>";
echo ($value[$getstats[$i]]);
echo "</td>";
}
echo "</tr>";
}
echo "</tbody>"; // <<< HERE
I'm wondering is it because the data type? http://www.datatables.net/manual/data tells you that the accepted data types are arrays, objects, and instances.
No, your code its fine as manual says Data can be read from DOM. You need arrays/objects/instances if you create table straight from javascript.
See below:
DOM
When DataTables starts up, it will automatically check the table it is operating on for data that already exists inside it and use it for the table (note that it will throw this data away if you pass in data using data or ajax to get new data!). This is the simplest method of using DataTables - working with a regular HTML table.
Note that when using a DOM sourced table, DataTables will use arrays as the data source (see above) by default, although you could use the columns.data option to have it construct objects for the row data instead.
http://www.datatables.net/manual/data#DOM
Your table structure was not correct :
<html>
<head>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="http://liveviewtest.byethost7.com/DataTables-1.10.9/media/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" src="http://liveviewtest.byethost7.com/DataTables-1.10.9/media/js/jquery.js"></script>
<!-- DataTables -->
<script type="text/javascript" src="http://liveviewtest.byethost7.com/DataTables-1.10.9/media/js/jquery.dataTables.js"></script>
<!--<link rel="stylesheet" type="text/css" href="http://liveviewtest.byethost7.com/style.css">-->
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
$('#mytable').DataTable();
});
</script>
<table id="mytable" border ="1" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Kills</th>
<th>Death Total</th>
<th>Suicides</th>
<th>Bears</th>
<th>Wolves</th>
<th>Helicopter</th>
<th>Falling</th>
<th>Cold</th>
<th>Explosions</th>
<th>Barricade</th>
<th>Player Deaths</th>
</thead>
<tbody>
<tr>
<td>hpnotiq</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>TacticalNuke735</td><td>1</td><td>12</td><td>12</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>.buckisM</td><td>2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Mrs Phluffy</td><td>0</td><td>4</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>My buddy's goin'a jail</td><td>6</td><td>134</td><td>126</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>8</td></tr><tr><td>marble</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Sir Joe</td><td>0</td><td>5</td><td>2</td><td>0</td><td>0</td><td>2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>StryX</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Haroth</td><td>6</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Mr Sephy</td><td>2</td><td>6</td><td>4</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Solblade531</td><td>2</td><td>4</td><td>2</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Vavbro</td><td>3</td><td>14</td><td>8</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>6</td></tr><tr><td>Heisenberg</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>アッパーおっぱい</td><td>3</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Tallsockboy</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>CHAPYSIX</td><td>1</td><td>2</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Bik</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Totes MiGoats</td><td>0</td><td>8</td><td>5</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>2</td></tr><tr><td>Blunted Out'cha Mind</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Jubby</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>That0neGuy</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Nuclear</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>michaelswansey</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>kapiowai</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Kami</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Pika</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>WC Visuals</td><td>0</td><td>2</td><td>2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>STUDNASTY</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>masternubb</td><td>0</td><td>2</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Bignubbb</td><td>2</td><td>5</td><td>4</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>BAAABBYNUBB</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Squirt</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Fluffy</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>| Albatross</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>inmate #42069 weston gayboy</td><td>10</td><td>9</td><td>5</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>3</td></tr><tr><td>isaiahyo</td><td>0</td><td>8</td><td>3</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>2</td><td>3</td></tr><tr><td>Vortex</td><td>1</td><td>5</td><td>3</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td></tr><tr><td>General Pro</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Ecchi Sketchy</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>a e s t h e t i c</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>TheS1mpleGuy2Know</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>♥JaPierDoLe™</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>JaidenV</td><td>1</td><td>2</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>FaceEatingTumor</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>Jfrisk</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Kilgore</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>chilmonik</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>chrishawsome</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>s4MPL3</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Dan Gleasak</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tbody>
</table>
</body>
</html>

Dynamic data population in table form with Code Igniter

I have a pretty simple question, but for some reason I am drawing a blank. I have the following code in my view file, and I want to display the results in a two column table, so the first entry would be on the left, the next would be on the right then the next one after that would be below the first row, and eventually I will use the pagination class (haven’t gotten that far yet) For some reason I can not figure out how to get the results to display in a 2 column format… only one. Any help would be greatly appreciated.
Ideally I would like to have 4 columns, but the code below was started with just the idea of 2 columns.
Thanks!
<table>
db->query($sql);
foreach ($query->result() as $row)
{
echo("");
echo("");
echo $row->Title;
echo ("<br/>");
?>
<img name="<?php echo $row->Thumb;?>" src="../uploaded/portfolio/thumbs/<?php echo $row->Thumb;?>" alt="">
<?php
echo("<br/>");
echo $row->DescText;
echo("</td>");
echo("<td>");
// Display next picture here
echo("</td>");
echo("</tr>");
}
?>
../
Your code example is rather confusing, but I think from your description that you're trying to do something like this:
<table>
<tr>
<?php $i = 0; foreach($query->result() as $row): ?>
<?php if ($i % 2 == 0): ?>
</tr><tr>
<?php endif; ?>
<td>
<?php //whatever you want to put in your column goes here; ?>
</td>
<?php $i++; endforeach; ?>
</tr>
</table>
If you want the table to be four rows across, just change the "if ($i % 2 == 0)" to "if ($i % 4 == 0)".

Categories