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 8 1488
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
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;
}
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
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
..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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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: ' ....
|
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...
|
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...
|
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...
|
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...
| |
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"...
|
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...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |