Faq split in columns

18 posts by 6 authors in: Forums > CMS Builder
Last Post: July 25, 2010   (RSS)

By thenetgirl - June 23, 2010

I know this is simple just not thinking like Spock today[:)]

I have a basic FAQ

I want say 4 questions in one column and the rest on the other side.

http://www.californialandlordsolutions.com/2010/FAQ.php

Thanks
Patricia

www.thenetgirl.com

Re: [thenetgirl] Faq split in columns

By Jason - June 23, 2010

Hi,

Basically what you'll do is set a counter just before your foreach loop. This counter will increment after each record outputted. Once the counter reaches 4 (or whatever number you want), you can out put tags to start a new column (using <div> tags for example).

Hope this points you in the right direction. If you can attach your FAQ.php file I can take a closer look.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Faq split in columns

By thenetgirl - June 23, 2010

Here is the file.
Patricia

www.thenetgirl.com
Attachments:

faq.php 4K

Re: [chris] Faq split in columns

By thenetgirl - June 23, 2010

ok so on the second column do i start with 5???
Patricia

www.thenetgirl.com

Re: [thenetgirl] Faq split in columns

By Chris - June 23, 2010

Hi thenetgirl,

I'm not sure what you mean. The next column will automatically start with the 5th record. Have you tried out the change?
All the best,
Chris

Re: [chris] Faq split in columns

By thenetgirl - June 23, 2010

yes

then it gave me all in both columns - put this on both sides

<?php $count = 0 ?> <?php foreach ($faqRecords as $record): ?>
<b> <?php echo $record['question'] ?></b><br/>
<?php echo $record['answer'] ?><br/>
<?php if ($count++ == 4): ?>
<br/> <?php endif ?>

<?php endforeach ?>

http://www.californialandlordsolutions.com/2010/FAQ.php

pg
Patricia

www.thenetgirl.com

Re: [thenetgirl] Faq split in columns

By Donna - June 23, 2010

Hi there,

You won't want to duplicate the code, you'll only put it in there once. What it basically says is "After the 4th entry, print this other code. Then keep going."

That "other code" should be whatever you need to separate the two columns, that's the bit you'll want to experiment on.

For example, if you had a simple two column table like this:

<table>
<tr>
<td>
Column 1
</td>
<td>
Column 2
</td>
</tr>
</table>

....you'd turn that into this:


<table>
<tr>
<td>

<?php $count = 0 ?> <?php foreach ($faqRecords as $record): ?>
<b> <?php echo $record['question'] ?></b><br/>
<?php echo $record['answer'] ?><br/>
<?php if ($count++ == 4): ?>
</td><td> <?php endif ?>

</td>
</tr>
</table>

Does that make sense? :)
Donna

--
support@interactivetools.com

Re: [Donna] Faq split in columns

By thenetgirl - June 23, 2010

It does make sense

but it not doing anything no matter what i put it displays all questions and answers in both columns.
Patricia

www.thenetgirl.com

Re: [Donna] Faq split in columns

By Chris - June 23, 2010

Hi thenetgirl,

You can do it with two foreaches as well, if you want to. In that case your first foreach should start like this:

<?php $count = 0 ?>
<?php foreach ($faqRecords as $record): ?>
<?php if ($count++ >= 4) { continue; } ?>


...and your second column's foreach should start like this:

<?php $count = 0 ?>
<?php foreach ($faqRecords as $record): ?>
<?php if ($count++ < 4) { continue; } ?>


Does that help?
All the best,
Chris