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 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
www.thenetgirl.com
Re: [thenetgirl] Faq split in columns
By Jason - June 23, 2010
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
www.thenetgirl.com
Re: [thenetgirl] Faq split in columns
By Chris - June 23, 2010
Try replacing this:
<?php foreach ($faqRecords as $record): ?>
...with this:
<?php $count = 0 ?>
<?php foreach ($faqRecords as $record): ?>
<?php if ($count++ == 4): ?>
</div><blockquote></td><td><blockquote><div>
<?php endif ?>
You'll need to experiment with the HTML in there. That will be output just before the fifth record.
I hope this helps! Please let us know if you have any questions.
Chris
Re: [chris] Faq split in columns
By thenetgirl - June 23, 2010
www.thenetgirl.com
Re: [thenetgirl] Faq split in columns
By Chris - June 23, 2010
I'm not sure what you mean. The next column will automatically start with the 5th record. Have you tried out the change?
Chris
Re: [chris] Faq split in columns
By thenetgirl - June 23, 2010
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
www.thenetgirl.com
Re: [thenetgirl] Faq split in columns
By Donna - June 23, 2010
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? :)
--
support@interactivetools.com
Re: [Donna] Faq split in columns
By thenetgirl - June 23, 2010
but it not doing anything no matter what i put it displays all questions and answers in both columns.
www.thenetgirl.com
Re: [Donna] Faq split in columns
By Chris - June 23, 2010
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?
Chris