473,226 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

Setting a varialble using a variable

jj
Trying to understand the manual regarding variables to solve the
following.

I'm working with Drupal CMS and have a loop to retrieve values that
are normally fetched by using this variable: $node-
>field_screen_1_caption[0]['view']. The loop should run n times,
incrementing that number 1 so next variable is $node-
>field_screen_2_caption[0]['view'].
Here's what I'm trying in my loop to change that number in the
variable using $i:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = 'node->field_screen_'.$i.'_caption[0][\'view\']';
print $$cap;
}

Doesn't work obviously. Any suggestions for a PHP amateur.

Thanks,
jj
Nov 27 '07 #1
8 1482
On Nov 27, 8:40 pm, jj <jjwalke...@gmail.comwrote:
Trying to understand the manual regarding variables to solve the
following.

I'm working with Drupal CMS and have a loop to retrieve values that
are normally fetched by using this variable: $node->field_screen_1_caption[0]['view']. The loop should run n times,

incrementing that number 1 so next variable is $node-
field_screen_2_caption[0]['view'].

Here's what I'm trying in my loop to change that number in the
variable using $i:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = 'node->field_screen_'.$i.'_caption[0][\'view\']';
print $$cap;

}

Doesn't work obviously. Any suggestions for a PHP amateur.

Thanks,
jj
eval() - http://php.net/eval

for ($i = 1; $i <= $number_of_screens; $i++) {
eval("\$cap = \$node->field_screen_{$i}_caption[0][\"view\"];");
print $cap;
}

--
Kailash Nadh | http://kailashnadh.name
Nov 27 '07 #2
jj
Excellent. Thanks, Kailash! I wouldn't have known what to look for.
jj
eval() -http://php.net/eval

for ($i = 1; $i <= $number_of_screens; $i++) {
eval("\$cap = \$node->field_screen_{$i}_caption[0][\"view\"];");
print $cap;

}
Nov 27 '07 #3
On Tue, 27 Nov 2007 21:40:24 +0100, jj <jj********@gmail.comwrote:
Trying to understand the manual regarding variables to solve the
following.

I'm working with Drupal CMS and have a loop to retrieve values that
are normally fetched by using this variable: $node-
>field_screen_1_caption[0]['view']. The loop should run n times,
incrementing that number 1 so next variable is $node-
>field_screen_2_caption[0]['view'].

Here's what I'm trying in my loop to change that number in the
variable using $i:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = 'node->field_screen_'.$i.'_caption[0][\'view\']';
print $$cap;
}

Doesn't work obviously. Any suggestions for a PHP amateur.
echo $node->{'field_screen_'.$i.'_caption'}[0]['view']

It has some serious flaws in design if you have to use it like that though.
--
Rik Wasmus
Nov 27 '07 #4
On Nov 27, 9:18 pm, jj <jjwalke...@gmail.comwrote:
Excellent. Thanks, Kailash! I wouldn't have known what to look for.
;) np. You're welcome!
jj
eval() -http://php.net/eval
for ($i = 1; $i <= $number_of_screens; $i++) {
eval("\$cap = \$node->field_screen_{$i}_caption[0][\"view\"];");
print $cap;
}
--
Kailash Nadh | http://kailashnadh.name
Nov 27 '07 #5
..oO(jj)
>Excellent. Thanks, Kailash! I wouldn't have known what to look for.
Not really. Eval is evil.

What about using an array instead?

Micha
Nov 27 '07 #6
Kailash Nadh wrote:
On Nov 27, 8:40 pm, jj <jjwalke...@gmail.comwrote:
>Trying to understand the manual regarding variables to solve the
following.

I'm working with Drupal CMS and have a loop to retrieve values that
are normally fetched by using this variable: $node->field_screen_1_caption[0]['view']. The loop should run n times,

incrementing that number 1 so next variable is $node-
>>field_screen_2_caption[0]['view'].
Here's what I'm trying in my loop to change that number in the
variable using $i:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = 'node->field_screen_'.$i.'_caption[0][\'view\']';
print $$cap;

}

Doesn't work obviously. Any suggestions for a PHP amateur.

Thanks,
jj

eval() - http://php.net/eval

for ($i = 1; $i <= $number_of_screens; $i++) {
eval("\$cap = \$node->field_screen_{$i}_caption[0][\"view\"];");
print $cap;
}

--
Kailash Nadh | http://kailashnadh.name
Ewww, eval really?

Variable Variables -
http://au.php.net/manual/en/language...s.variable.php
- is probably closer to what you want.

Example:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = '$node->field_screen_' . $i . '_caption[0][\'view\']';
print $$cap;
}

Should work! However I *strongly* suggest using an array.

- Michael
Nov 28 '07 #7
Michael wrote:
Kailash Nadh wrote:
>On Nov 27, 8:40 pm, jj <jjwalke...@gmail.comwrote:
>>Trying to understand the manual regarding variables to solve the
following.

I'm working with Drupal CMS and have a loop to retrieve values that
are normally fetched by using this variable:
$node->field_screen_1_caption[0]['view']. The loop should run n times,

incrementing that number 1 so next variable is $node-

field_screen_2_caption[0]['view'].
Here's what I'm trying in my loop to change that number in the
variable using $i:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = 'node->field_screen_'.$i.'_caption[0][\'view\']';
print $$cap;

}

Doesn't work obviously. Any suggestions for a PHP amateur.

Thanks,
jj

eval() - http://php.net/eval

for ($i = 1; $i <= $number_of_screens; $i++) {
eval("\$cap = \$node->field_screen_{$i}_caption[0][\"view\"];");
print $cap;
}

--
Kailash Nadh | http://kailashnadh.name

Ewww, eval really?

Variable Variables -
http://au.php.net/manual/en/language...s.variable.php
- is probably closer to what you want.

Example:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = '$node->field_screen_' . $i . '_caption[0][\'view\']';
print $$cap;
}

Should work! However I *strongly* suggest using an array.

- Michael
Agh, whoops what i meant was...

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = '$node->field_screen_' . $i . '_caption';
print $$cap[0]['view'];
}

- Michael
Nov 28 '07 #8
jj wrote:
Trying to understand the manual regarding variables to solve the
following.

I'm working with Drupal CMS and have a loop to retrieve values that
are normally fetched by using this variable: $node-
>field_screen_1_caption[0]['view']. The loop should run n times,
incrementing that number 1 so next variable is $node-
>field_screen_2_caption[0]['view'].

Here's what I'm trying in my loop to change that number in the
variable using $i:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = 'node->field_screen_'.$i.'_caption[0][\'view\']';
print $$cap;
}

Doesn't work obviously. Any suggestions for a PHP amateur.

Thanks,
jj
As you can see by the replies there are many ways to do this... yet
another:

for ($i = 1; $i <= $number_of_screens; $i++) {
$cap = "node->field_screen_{$i}_caption[0]['view']";
echo $$cap;
}

Norm
Nov 28 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: skeeterbug | last post by:
i have a program that will display a number of diffferent results depending on the situation. one example of the code looks like <?php if(isset($_SESSION)) { print 'You entered: ' ....
5
by: Aamer Nazir | last post by:
Hi, I am having problems setting the value of a variable in a SQL String that I have to create dynamically in my procedure. The code that I currently have is as follows: set...
2
by: TF | last post by:
hi, i am using a ListBox control on a windows form using VB.Net. when i set the DataSource property of the control to an ArrayList it fires following events in this order: SelectedIndexChanged...
8
by: David McDivitt | last post by:
I need to set tabs on java generated pages. Pages have four sections: header, sidebar, body, and footer. The sidebar and body change dynamically. The tab key must go to anchors, fields, and buttons...
6
by: shaan.shaan | last post by:
Hi I am trying to set an env. variable by exporting in unix environment on DB2. I am using export var_name=ON, but it is not taking the value of the var_name. This thing is working fine when I...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
0
by: nairjones | last post by:
Hi everyone help me iam having a problem passing a value to an sql variable thru VBA. I have a stored procedure declare @rec delete tablename where field1 = @rec the variable is to get a...
4
by: akshay01 | last post by:
Hi All, I am using the following code in which i am creating some textboxes and and as the for loop continues the name of the textboxes will also be unique for all the textboxes. now i want to...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.