Js obtains the element values of the php (ecshopsmarty template) array-php Tutorial

Source: Internet
Author: User
Js obtains the element value of the php (ecshopsmarty template) array ecshop smarty php

I recently modified PHP stuff (ecshop) and encountered a problem. I sincerely ask you for help:
1. assign values using the smarty template on the php page. some codes are as follows:

While ($ row = $ db-> FetchRow ($ res ))
{
If ($ cur = null)
$ Cur = $ row ['Template _ id'];
$ Modelrow [$ row ['Template _ id'] = $ row ['Template _ id'];
$ Modelcontent [$ row ['Template _ id'] = trim ($ row ['Template _ content']);
$ Modelplates [$ row ['Template _ id'] = $ row ['Template _ subobject']. "-$ row [content_category]-". $ row ['Template _ subject_second '];
// Echo $ modelcontent [$ row ['Template _ id'];

}
$ Smarty-> assign ('cur', $ cur );
$ Smarty-> assign ('modelrow', $ modelrow );
$ Smarty-> assign ('modelplates', $ modelplates );
$ Smarty-> assign ('modelcontent', $ modelcontent );
/* End */

$ Modelcontent array is passed to the front-end dwt template in the js function:
1. get a variable value temp = $ ("# temp"). val (); (this variable value is 1, 2, 3, and so on. there is no problem with obtaining it .)
2. var a = '{$ modelcontent. temp} '; Step 2: Use the variable to get an element value of $ modelcontent, but it is empty. I don't know how to get it; during the test, var a = '{$ modelcontent.1}' can still be obtained if the subscript of the array is 1.
Now the question is, how can we get the corresponding subscript value of the array based on known variables? There are other solutions. thank you!


Reply to discussion (solution)

Change
Var a =' ';
Alert (a); check the result.

Change
Var a =' ';
Alert (a); check the result.
The displayed value is also blank. in the browser, php has: var a = '';

Var a = '{$ modelcontent.' + temp + '}';
Alert ();
Try again.

Var a = '{$ modelcontent.' + temp + '}';
Alert ();
In this way, the same value is null,

Http://www.zui88.com/blog/view-261.html
See if it can help you

In the Smarty template, the key name of the array is the value of a variable. how to display the value corresponding to the key name
In: backend program
The question is a bit difficult.

Php has assigned an array to the template. the array information is as follows:

$ Config = array (

1 => 'zhongshan ',

2 => 'ishigaki'

);

The field in the database storage area records the key name of the array, for example, 1. now the template displays: Zhongshan.

If this is the case, an error is returned:

{{$ Config. $ row. region }}

The correct syntax on the template is: {$ config [$ row. region]}

The problem we encountered today is even more complicated. database fields store configuration serialization, so deserialization is also required when retrieving region information. there must be a value assignment process in the middle:

{Assign var = param value = $ l. params | unserialize }}

Then $ param. region can get the value of 1.

When {lection} is there a KEY, isn't it ???

Either when mass transfer is performed, one column of storage KEY is transferred.

When {lection} is there a KEY, isn't it ???

You can either upload a column to store KEY php and smarty for the first time during mass transfer. please give me some advice. thank you.

Will the smarty cycle be used? I'm talking about Loop arrays. Is there a key column. You can directly use
I just wrote an error.
{Section name = loop = $ v}
{$ V [loop]. array key value}
{/Section}

Print the key to see if the key is another number, and press the KEY to get the correct value.

Will the smarty cycle be used? I'm talking about Loop arrays. Is there a key column. You can directly use
I just wrote an error.
{Section name = loop = $ v}
{$ V [loop]. array key value}
{/Section}

Print the key to see if the key is another number. as a result, the correct numeric dwt template cannot be obtained by the KEY. how can this problem be solved by the section tag? Do you still need any references or other modifications to use section?

Wait for help

Thank you for your help! You have solved the problem by yourself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.