Multi column - again!

14 posts by 4 authors in: Forums > CMS Builder
Last Post: December 15, 2010   (RSS)

By terryally - December 14, 2010 - edited: December 14, 2010

Hi Jason,

I want the same effect as if it were tables. If there are 11 records, then split the output into two columns.

The purpose of col2 was simply to float the column left as I would normally.

The code is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
.col1 {width: 250px; height: 325px;border-style:solid;border-width:5px;}
.col2 {width: 250px; height: 325px;float:left;border-style:solid;border-width:2px;border-color: #ff0000;}
.top {width:250px;height:73px;background:url(/images/sticky-note-yellow_01.gif) no-repeat;}
.inner {width:100%;background:url(/images/sticky-note-yellow_02.gif) repeat-y; float:left;}
.inner_text {color: blue;font-family: Verdana, cursive;font-style: oblique;font-size: 12px;padding-left: 15px;width: 200px; }
.end {width:250px;height:120px;background:url(/images/sticky-note-yellow_03.png) no-repeat;float:left;}
.name {font-family: Verdana;font-style: italic;padding-right: 15px;text-align: right;}
span.date {color: black;font-family: Verdana;font-size: 10px;line-height: 15px;}
.clear { clear:both;}
</style>
</head>

<body>

<?php foreach ($public_inputsRecords as $record): ?>
<div class="col1">
<div class="top"></div>
<div class="inner">
<div class="inner_text">
<span class="date">Posted: <?php echo date("D, M j Y", strtotime($record['createdDate'])) ?></span><br />
<?php echo $record['request'] ?><br />
<div class="name">- <?php echo $record['screen_name'] ?>, <?php echo $record['country'] ?></div>
</div>
</div>
<div class="end"></div></div>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></div><div class="col2"><?php endif ?>
<?php endforeach ?>
</div>


<?php if (!$public_inputsRecords): ?>
<div class="top"></div>
<div class="inner">
<div class="inner_text">
There are no current requests.
</div>
</div>
<div class="end"></div>
<?php endif ?>

</body>
</html>



Thanks for your help.
Terry

Re: [terryally] Multi column - again!

By Jason - December 14, 2010

Hi Terry,

The problem with using $maxCols=2 is that it will be triggered every other record. What you actually want to do is trigger this change once, at the half way point. Try something like this:

<?php $half = intval(count($public_inputsRecords)/2);?>
<?php foreach ($public_inputsRecords as $record): ?>
<div class="col1">
<div class="top"></div>
<div class="inner">
<div class="inner_text">
<span class="date">Posted: <?php echo date("D, M j Y", strtotime($record['createdDate'])) ?></span><br />
<?php echo $record['request'] ?><br />
<div class="name">- <?php echo $record['screen_name'] ?>, <?php echo $record['country'] ?></div>
</div>
</div>
<div class="end"></div></div>
<?php if (@++$count == $half): ?></div><div class="col2"><?php endif ?>
<?php endforeach ?>
</div>


This should be more what you're looking for.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By terryally - December 14, 2010 - edited: December 14, 2010

Hi Jason,

Below is the slight change to the variable to put the divisor outside of the bracket (typo).

<?php $half = intval(count($public_inputsRecords))/2;?>

This however just parsed everything into a single column because the number of records was an odd number hence $half = x.5 records.

I added a second line variable to round the number:


<?php $half = round($half);?>

This then splits the records at the halfway point but but in the same way that I reported it in my previous email i.e.

</div><div class="col2"> <div class="col1">

</div><div class="col1">

</div> (etc etc etc)



So what the endif is doing after class col2 is terminating it and reintroducing class col1.

Any further thoughts

Terry
P.S. Apology for calling you Chris in prev msg. I edited it.