Wildcards - Looking Up a Range of Similar Fields?

5 posts by 3 authors in: Forums > CMS Builder
Last Post: August 23, 2011   (RSS)

Re: [Perchpole] Wildcards - Looking Up a Range of Similar Fields?

By Jason - August 22, 2011

Hi,

Could you give an example of how you would use this wildcard/array? Let us know and we'll see if we can make any suggestions.

Thanks
---------------------------------------------------
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] Wildcards - Looking Up a Range of Similar Fields?

Hi, Jason -

I'm trying to refine a system for choosing which margin widgets appear on a page.

Currently, when a user creates a category page he can choose 6 widgets to appear in the margin. He/she does this by means of 6 identical drop-down menus listing the available widgets.

So,

field1 might equal widget5

field2 might equal widget3

field3 might equal widget8

field4 might equal widget1

and so on...

Each selection returns a number - which forms an array. When the page is called, I use some very basic code to pull the chosen widgets into the margin of the page.

It's basic and rather clunky - but does the job!

(NB: Initially, instead of 6 lists, I used just one multi-select menu. It was a lot cleaner but it didn't allow you to manipulate the widget order.)

I posted my question because I thought I might learn something new about constructing arrays. It seemed even more clunky to have to list each field in the array code. I just wondered if there was a smarter way of doing it?

:0)

Perch

Re: [Perchpole] Wildcards - Looking Up a Range of Similar Fields?

By robin - August 23, 2011

Hey,

You could use a loop and an if to get all fields that start with 'field'. Something like:

foreach($record[0] as $key => $value) {
if(substr($key,0,5) == 'field') {
$myArray[] = $value
}
}


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Wildcards - Looking Up a Range of Similar Fields?

Hi, Robin -

Brilliant! Just what I was hoping for.

Thanks,

:0)

Perch