/    Sign up×
Community /Pin to ProfileBookmark

How to use a variable as the index for a table?

I want to use a variable to indicate a index in an array, but it doesn’t work. Can anybody help me about that? My codes are:

<body onload=”timeout = checkTimeout(currPage,<?php echo $instance ?>)” onUnload=”cancelTimeout(timeout,currPage)”>

<form name=”Service” onsubmit=”javascript:return validate()”
action=”submit.php?state=<?php echo($instance)?>&section=Outbound <?php echo($tatal_service) ?>” method=”post”>

<table bgbolor=”White” width=”100%” id=”outbound_table”>

<tbody>

<tr>
<td bgcolor=”#0033CC” align=”center” colspan=”6″>
<font face=”Verdana,Arial” size=”2″ color=”#FFFFF”><b>Outbound Services</b></font>
</td>
</tr>

<tr bgcolor=”#FFFFD6″ id=”service_header”>
<th>Name</th>
</tr>

<tr bgcolor=”#CCCCCC” id=”serviceList”>
<td align=”center” id=”service_name”>
<select name=”services”>
<?php $value = $config[‘Outbound $tatal_service’][‘services’]; if ($value == “”) $value = “HTTP” ?>
<option value=”HTTP” <?php if ($value == “HTTP”) { echo “selected”; } ?> >HTTP</option>
<option value=”HTTPS” <?php if ($value == “HTTPS”) { echo “selected”; } ?> >HTTPS</option>
<option value=”pcanywhere” <?php if ($value == “pcanywhere”) { echo “selected”; } ?> >pcAnyWhere</option>
</select>
</td>
</tr>

$tatal_service is a global variable and it is now set as 1.

If I use [I]$config[‘Outbound 1’][‘services’][/I], then after I input the service name in the GUI and refresh the page, the previously input value can be shown in the page. However, if I use [I]$config[‘Outbound $tatal_service’][‘services’][/I], then the refreshed page can’t show the input vaule. But I have set $tatal_service as 1.

Thanks in advance!

Rui

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 12.2005 — You have to use double-quotes when you want variables to be interpolated:
[code=php]
$config["Outbound $tatal_service"]['services']
[/code]
Copy linkTweet thisAlerts:
@reinmontrealauthorOct 12.2005 — Thanks, NogDog! It works. ?
×

Success!

Help @reinmontreal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...