Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Alernating alignment in a Repeating Region

Explorer ,
Sep 13, 2007 Sep 13, 2007
Hi everyone!

I have a particular problem with a client site, and I'm not sure if there is a solution at all. I'm hoping all you PHP guru's might have some suggestions.

I have a page that is displaying items from a restaurant menu. I have the images and the text in a MySQL table and the are displaying correctly in a repeating region.

The problem is that the client wants the alignment of the image in each row to alternate (i.e. The first row has the image aligned to the right and the next row has the image aligned to the left and so on.)

Is this even possible? I would really appreciate any insights or solutions you can offer.

Please help.
TOPICS
Server side applications
413
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2007 Sep 13, 2007

"SaigonJeff" <webforumsuser@macromedia.com> wrote in message
news:fcc41d$g8o$1@forums.macromedia.com...
> Hi everyone!
>
> I have a particular problem with a client site, and I'm not sure if there
> is a
> solution at all. I'm hoping all you PHP guru's might have some
> suggestions.
>
> I have a page that is displaying items from a restaurant menu. I have the
> images and the text in a MySQL table and the are displaying correctly in a
> repeating region.
>
> The problem is that the client wants the alignment of the image in each
> row to
> alternate (i.e. The first row has the image aligned to the right and the
> next
> row has the image aligned to the left and so on.)
>
> Is this even possible? I would really appreciate any insights or solutions
> you
> can offer.

what if you had a field in the database to define a CSS class for the IMG?
I.e., define some class like ".left" and ".right" and put that info into the
db, then in the row put the dynamic data into the IMG tag? This presumes
that you know the specific order in which things are being displayed.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2007 Sep 13, 2007
.oO(Hunter Elliott)

>"SaigonJeff" <webforumsuser@macromedia.com> wrote in message
>news:fcc41d$g8o$1@forums.macromedia.com...
>>
>> I have a page that is displaying items from a restaurant menu. I have the
>> images and the text in a MySQL table and the are displaying correctly in a
>> repeating region.
>>
>> The problem is that the client wants the alignment of the image in each row to
>> alternate (i.e. The first row has the image aligned to the right and the next
>> row has the image aligned to the left and so on.)
>>
>> Is this even possible? I would really appreciate any insights or solutions you
>> can offer.
>
>what if you had a field in the database to define a CSS class for the IMG?

Really bad idea.

>I.e., define some class like ".left" and ".right" and put that info into the
>db, then in the row put the dynamic data into the IMG tag? This presumes
>that you know the specific order in which things are being displayed.

Exactly, and if you change the order or insert/remove an item you would
have to adjust all others. Doing it with CSS is the right way, but it
should be done on output, which is fairly easy in a loop. Some ideas:

A counter variable, increased in every loop, could be checked for being
odd or even. A boolean variable could be checked for TRUE and negated in
every loop. An array lookup table could be used and would allow even
more alternating styles ... there are many different ways to achieve
that. In a few years (20 maybe 😉 ) it will be even possible without any
additional markup, just with CSS alone. Anyway.

Obviously the OP doesn't know that much PHP to code that by hand, so it
would help to see the DW-generated code he already has at the moment.
Then it's easy to modify it as needed. A URL of the current page would
be helpful as well.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2007 Sep 13, 2007
"SaigonJeff" <webforumsuser@macromedia.com> wrote in message
news:fcc41d$g8o$1@forums.macromedia.com...
> Hi everyone!
>
> I have a particular problem with a client site, and I'm not sure if there
> is a
> solution at all. I'm hoping all you PHP guru's might have some
> suggestions.
>
> I have a page that is displaying items from a restaurant menu. I have the
> images and the text in a MySQL table and the are displaying correctly in a
> repeating region.
>
> The problem is that the client wants the alignment of the image in each
> row to
> alternate (i.e. The first row has the image aligned to the right and the
> next
> row has the image aligned to the left and so on.)
>
> Is this even possible? I would really appreciate any insights or solutions
> you
> can offer.
>
> Please help.


The term you're looking for is Alternating Row colors, there are extensions
that will make it easier to apply them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2007 Sep 14, 2007
> The problem is that the client wants the alignment of the image in each
> row to
> alternate (i.e. The first row has the image aligned to the right and the
> next
> row has the image aligned to the left and so on.)
>
> Is this even possible? I would really appreciate any insights or solutions
> you
> can offer.

If this is a standard DW repeat region, first set a variable before the loop
somewhere:

<?php $currentRow = 0;?>

Then, on the image tag, add some CSS/PHP

<img style="float: <?php echo($currentRow++ % 2) ? "left" : "right";?>"
src="etc etc" />

It could be done with a CSS class too.


--
--
Tom Muck, Adobe Community Expert
Dreamweaver Extensions/Articles -- http://www.tom-muck.com/
Cartweaver Development Team - http://www.cartweaver.com/
Extending Knowledge Daily - http://www.communitymx.com/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 15, 2007 Sep 15, 2007
LATEST
To: Mr. Muck

I am only just now finishing Fnd PHP for DW8 and just today installed a few of your extensions to create an image gallery. I was going to suggest the same thing since I learned it a few chapters ago. You beat me to the chase and I'm glad you did. I can't think of how exactly I was going to advise him to do it, but I know that this is a much more elegant means than I would have thought of. Kudos!
Todd
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines