to fill a select with json javascript from arrays [message #175072] |
Wed, 10 August 2011 12:13  |
nawfer
Messages: 34 Registered: August 2011
Karma: 0
|
Member |
|
|
in JSON/javascript if I have 3 php’s array, how can insert their values in
3 selects?
the select also must to be dependant; example Car Brand->Car
Model->Accessories
I look guide but cannot understand how solve the problem
ARRAY BRAND
brand[01]='Brand 1';
....
brand[20]='Brand 20';
ARRAY MODEL (every brand have 3 models,total 60 models)
model[01][m01]=’model m01 of brand 1’;
model[01][m02]=’model m02 of brand 1’;
....
model[20][m59]=‘model m59 of brand 20’;
model[20][m60]=‘model m60 of brand 20’;
ARRAY ACCESSORIES (every models can to have n accessories; exmpl. m01-> 3
accessories,
m60 -> 2 access.)
accessories[m01][]=‘accessories 1 of model m01’;
accessories[m01][]=‘accessories 2 of model m01’;
accessories[m01][]=‘accessories 3 of model m01’;
……..
accessories[m60][]=‘accessories 1 of model m60’;
accessories[m60][]=‘accessories 2 of model m60’;
|
|
|
|
|
|
|
Re: to fill a select with json javascript from arrays [message #175078 is a reply to message #175077] |
Wed, 10 August 2011 21:19   |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 8/10/2011 3:48 PM, Bill B wrote:
> On 8/10/2011 1:26 PM, Jerry Stuckle wrote:
>> On 8/10/2011 12:16 PM, nawfer wrote:
>>>> This is actually a JavaScript/JSON question.
>>>
>>> but in the first step how can take the array php and have array js?
>>> I read json is solution but which is the correct code that can to work
>>> with
>>> my type of php array?
>>
>> You have to understand - PHP runs on the server, and javascript on the
>> client. By the time your javascript code executes, PHP has completed its
>> execution and terminated.
>>
>> So what you have to do in your PHP code is create the javascript code to
>> build the array then send the javascript code to the client.
>
> Jerry, out of curiosity, with the information you have, is there
> solution that is only PHP?
>
> Bill B
Not if he wants to use json. Other than that, I have no idea what he's
trying to do. But if it requires execution on the client, then
obviously not. However, if it could all be done server-side, then it
easily could.
But reading between the lines, I suspect he's using AJAX to refresh part
of a page after a search is performed. I don't know, though, and could
be way off.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
|
|
|
|
Re: to fill a select with json javascript from arrays [message #175089 is a reply to message #175088] |
Thu, 11 August 2011 22:42   |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
Paul Herber wrote:
> Thomas 'PointedEars' Lahn wrote:
>> nawfer wrote:
>>>> This is actually a JavaScript/JSON question.
>>> but in the first step how can take the array php and have array js?
>>> I read json is solution but which is the correct code that can to work
>>> with my type of php array?
>> RTFM: <http://php.net/json_encode> (there are examples there, too!)
>>
>> You would be well-advised to ignore Jerry Stuckle.
>
> I've learnt far more useful stuff from Jerry's posts than from anyone
> else's in this group. When he answers a question by directing the OP to
> another group he is always (FSVO always) right.
YMMV.
However, as you could have noticed, this is _not_ solely a JavaScript/JSON
question, as PHP has had a *built-in* function for creating JSON from PHP
arrays for quite some time (which is a Good Thing, as it spares you all the
looping and escaping). Subscribers of cljs, for example, do not need to
know that as there are various ways to create JSON. So that question is not
off-topic here, and it is not on-topic there.
Not knowing that (or knowing where to find it to give the correct answer)
but replying with somewhat correct, yet useless information nevertheless
("somewhat" because e.g., PHP is _not_ limited to the server side as
JavaScript is _not_ limited to the client side, and there is no "javascript"
to begin with – we have been over this) does _not_ count as a competent
answer in my book, and in my experience there have been few useful comments
from Jerry but a lot of unnecessarily rude and really useless ones by
comparison. Enough for me to ignore him (with one exception) and recommend
that to others similarly mistreated, which I usually do not do. Sorry, but
that's that.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(at)news(dot)demon(dot)co(dot)uk>
|
|
|
|
|
Re: to fill a select with json javascript from arrays [message #175092 is a reply to message #175091] |
Fri, 12 August 2011 10:39  |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 8/11/2011 11:24 PM, Bill B wrote:
> On 8/11/2011 7:53 PM, Jerry Stuckle wrote:
>> On 8/11/2011 5:05 PM, Bill B wrote:
>>> On 8/11/2011 4:50 PM, Thomas 'PointedEars' Lahn wrote:
>>>> You would be well-advised to ignore Jerry Stuckle. The record shows
>>>> that he
>>>> seldom knows what he is talking about but unfortunately compensates
>>>> that
>>>> with uncalled-for rudeness.
>>>
>>> I will leave the issue of competency to those who are smarter. As to
>>> rudeness - he is blunt, but so are you. Bluntness in and of itself is
>>> not rude. You are not rude when you are blunt, and neither is he.
>>>
>>> Could you both profit from a visit with Dale Carnegie to win friends and
>>> influence people? Yes. Passing on doing so makes neither of you a lesser
>>> person.
>>>
>>> Glass houses.
>>>
>>> Bill B
>>
>> And you can take your self-righteous attitude and stick it where the sun
>> doesn't shine. That way it will be right next to your head.
>>
>> In case you can't figure it out - no one here gives a damn what you
>> think. And no one is going to change what they do, no matter how much
>> you troll your crap.
>
> It was a compliment and a defense, Jerry. Slow down on your reading.
>
> Bill B
I can read just fine, Bill. And I stand by my statement.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|