3 coloumns listing + some more...

By Jason - July 27, 2010

Hi,

I think it may have to do with the script. The id for the div is supposed to be the filename, not the file path.

Try changing it to this:
<div id="<?php echo $upload['filename'];?>" class="gallery_image">

Hope this helps.
---------------------------------------------------
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] 3 coloumns listing + some more...

By mingyq - July 27, 2010

Scratching my head, nope this didn't help either, any other suggestions? Would it help if I gave you the FTP login?

MingyQ

By Jason - July 29, 2010

Hi,

I took a look at the code, and it looks like in your Gallery.php page, your selecting information from a table that contains youtube links. This information is used to create flash objects. This is not happening in your gallery_test3.php page.

Because this is dealing with a third party script, it's a little more involved than what we deal with in the forum. We would be more than happy to look into this issue further through our consulting service:
www.interactivetools.com/hire-us/


Hope this helps.
---------------------------------------------------
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] 3 coloumns listing + some more...

By Rusty - February 17, 2011 - edited: February 17, 2011

I want to know why putting this within a foreach to list records (w/ a limit of 3 set within the table query) this works:

THIS WORKS
<?php $maxCols=3; if (@++$count % $maxCols == 0): ?><div class="plan_box last">
<?php else: ?><div class="one_third"><?php endif; ?>

THIS WORKS

Properly assigning DIV "one_third" to the first two div's, and then "plan_box last" to the third and final div.

But this:

<?php $counter = 0;
while ( $counter <= 1 ) {
echo "
<div class=\"one_third\">";
$counter = $counter + 1;
} echo "
<div class=\"plan_box last\">";
?>


makes all kinds of mumbo jumbo madness, doing what I want, but three times for each item listed within the FOREACH:
<div class="one_third"><div class="one_third"><div class="plan_box last">

It's not that I don't love the fact that I finally hammered this out, however, I just wish I knew what was going on with the % where it's checking to see if $maxCols is equal to zero. I see the IF statement, I see the @ sign (to suppress errors/warnings) I see the counter, but to me it seems backwards. Someone care to fill me in on the steps that are happening there?


BTW that works awesome, and will be very useful for defining custom CSS for the last item in a particular list (when used within a FOREACH).

Keywords I used to search. php counter auto increment list foreach multiple columns limit
Rusty

Re: [Rusty] 3 coloumns listing + some more...

By Rusty - February 17, 2011

One other thing When working with a List Page, how can you go about incorporating CMS FOREACH to set it up to make let's say a 3x3 grid, 3 rows of 3. Obviously some kind of counter would be necessary, to increment for each of the 9 records, and we can use the above code to force it to a new row...
Rusty

Re: [Rusty] 3 coloumns listing + some more...

By Jason - February 17, 2011

Hi Rusty,

"%" is the modulus operator in PHP, which means it returns the remainder of the the left hand side divided by the right hand side.

What this is doing is looking for multiples of 3. So every time $count is a multiple of 3, the answer will be 0:
ie
3 % 3 = 0
6 % 3 = 0
9 % 3 = 0
etc

This is a good way of handling it if you don't know how many records you'll actually be dealing with.


As for using a foreach to create a grid of 3 x 3, you could do something similar to this example:


<?php

$maxRows = 3;
$maxCols = 3;

$colCount = 0;
$rowCount = 1;

?>

<?php foreach ($productRecords as $record): ?>

<?php if($rowCount < $maxRows){ break;} ?>

<?php if (++$colCount % $maxCols == 0): ?>
<div class="plan_box last">
<?php $rowCount++ ;?>

<?php else: ?>
<div class="one_third">

<?php endif; ?>

<?php echo $record['title'];?>

</div>

<?php endforeach ?>


Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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