Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2777 > unrolled thread
| Started by | nawfer <novalidsforspam@alt.al> |
|---|---|
| First post | 2011-08-10 14:13 +0200 |
| Last post | 2011-08-11 00:12 +0000 |
| Articles | 14 — 7 participants |
Back to article view | Back to comp.lang.php
to fill a select with json javascript from arrays nawfer <novalidsforspam@alt.al> - 2011-08-10 14:13 +0200
Re: to fill a select with json javascript from arrays Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-08-10 14:51 +0200
Re: to fill a select with json javascript from arrays nawfer <novalidsforspam@alt.al> - 2011-08-10 18:16 +0200
Re: to fill a select with json javascript from arrays Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-10 13:26 -0400
Re: to fill a select with json javascript from arrays Bill B <me@privacy.net> - 2011-08-10 15:48 -0400
Re: to fill a select with json javascript from arrays Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-10 17:19 -0400
Re: to fill a select with json javascript from arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-08-11 22:50 +0200
Re: to fill a select with json javascript from arrays Bill B <me@privacy.net> - 2011-08-11 17:05 -0400
Re: to fill a select with json javascript from arrays Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-11 19:53 -0400
Re: to fill a select with json javascript from arrays Bill B <me@privacy.net> - 2011-08-11 23:24 -0400
Re: to fill a select with json javascript from arrays Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-12 06:39 -0400
Re: to fill a select with json javascript from arrays Paul Herber <paul@pherber.com> - 2011-08-11 22:56 +0100
Re: to fill a select with json javascript from arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-08-12 00:42 +0200
Re: to fill a select with json javascript from arrays Denis McMahon <denis.m.f.mcmahon@gmail.com> - 2011-08-11 00:12 +0000
| From | nawfer <novalidsforspam@alt.al> |
|---|---|
| Date | 2011-08-10 14:13 +0200 |
| Subject | to fill a select with json javascript from arrays |
| Message-ID | <1bvj3wor4c13g.yba8pdm1yhnv$.dlg@40tude.net> |
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’;
[toc] | [next] | [standalone]
| From | Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> |
|---|---|
| Date | 2011-08-10 14:51 +0200 |
| Message-ID | <4e427ea9$0$23883$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #2777 |
On 8/10/2011 2:13 PM, nawfer wrote:
> 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’;
>
Hi,
This is actually a JavaScript/JSON question.
What you probably need is something like this:
[Javascript]
for (var key in someArray){
var theValue = someArray[key];
// do stuff
}
which is a little like PHP's:
foreach ($someArray as $key => $theValue){
}
Whit that approach you'll have the key of some array, which you will
need in your accessories-array to look up the different values.
Regards,
Erwin Moller
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[toc] | [prev] | [next] | [standalone]
| From | nawfer <novalidsforspam@alt.al> |
|---|---|
| Date | 2011-08-10 18:16 +0200 |
| Message-ID | <17koe79k116aj.10mw3uyf7ueba$.dlg@40tude.net> |
| In reply to | #2779 |
> 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?
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-08-10 13:26 -0400 |
| Message-ID | <j1uevm$5il$1@dont-email.me> |
| In reply to | #2781 |
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. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Bill B <me@privacy.net> |
|---|---|
| Date | 2011-08-10 15:48 -0400 |
| Message-ID | <j1un8i$6fj$2@dont-email.me> |
| In reply to | #2782 |
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
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-08-10 17:19 -0400 |
| Message-ID | <j1usm0$bhc$3@dont-email.me> |
| In reply to | #2783 |
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@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-08-11 22:50 +0200 |
| Message-ID | <2378528.ArG6xLiZAS@PointedEars.de> |
| In reply to | #2781 |
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. The record shows that he seldom knows what he is talking about but unfortunately compensates that with uncalled-for rudeness. Please follow the recommendations in <http://www.netmeister.org/news/learn2quote.html>. 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@news.demon.co.uk>
[toc] | [prev] | [next] | [standalone]
| From | Bill B <me@privacy.net> |
|---|---|
| Date | 2011-08-11 17:05 -0400 |
| Message-ID | <j21g5p$h7$2@dont-email.me> |
| In reply to | #2791 |
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
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-08-11 19:53 -0400 |
| Message-ID | <j21q29$vtd$1@dont-email.me> |
| In reply to | #2792 |
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. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Bill B <me@privacy.net> |
|---|---|
| Date | 2011-08-11 23:24 -0400 |
| Message-ID | <j226d9$874$1@dont-email.me> |
| In reply to | #2795 |
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
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-08-12 06:39 -0400 |
| Message-ID | <j22vt5$5uo$1@dont-email.me> |
| In reply to | #2796 |
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@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Paul Herber <paul@pherber.com> |
|---|---|
| Date | 2011-08-11 22:56 +0100 |
| Message-ID | <bgj8479phocl1vd6kmgtv7shluvjuh1m1s@news.eternal-september.org> |
| In reply to | #2791 |
On Thu, 11 Aug 2011 22:50:33 +0200, Thomas 'PointedEars' Lahn <PointedEars@web.de> 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. -- Regards, Paul Herber, Sandrila Ltd. http://www.sandrila.co.uk/
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-08-12 00:42 +0200 |
| Message-ID | <2509953.OE10fRJf03@PointedEars.de> |
| In reply to | #2793 |
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@news.demon.co.uk>
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denis.m.f.mcmahon@gmail.com> |
|---|---|
| Date | 2011-08-11 00:12 +0000 |
| Message-ID | <4e431e82$0$17122$a8266bb1@newsreader.readnews.com> |
| In reply to | #2777 |
On Wed, 10 Aug 2011 14:13:10 +0200, nawfer wrote: > in JSON/javascript .... If you're trying to create a json string from PHP array data to send to a javascript application: http://uk2.php.net/manual/en/function.json-encode.php If you're trying to create a PHP array or object from json data that has been created by a javascript application: http://uk2.php.net/manual/en/function.json-decode.php if you're trying to create json data with javascript, or create a javascript object from json data, try asking in a javascript newsgroup or forum, not a php one. If you're trying to send a string of json encoded data in response to a client side ajax style request: <?php // process the request // create the data string to send echo $json_encoded_string; ?> Note that generally you don't want to include any other output, and specifically no html tags. Rgds Denis McMahon
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web