logs archiveIRC Archive / Freenode / #php / 2015 / September / 14 / 1
AcidReign
Kalio_: it's better to json_encode() data, write it ti a javascript variable, then have javascript code that reads/processes that variable
Kalio_
Hm do u have a example for this?
AcidReign
json_encode takes care of escaping things, so that a user can't just write javascript code into a form field, that later gets executed in another user's browser
Kalio_: also, it's better to separate javascript from php, have php send data to the javascript, not have php generate the javascript
Kalio_
Okay but how can I seperate it. I need the data ot of the db
AcidReign
code generation is a complex and advanced practice, that is very easy to get wrong and make extremely insecure
Kalio_
Something like that:
http://pastebin.com/ZFCZeJ42
?
AcidReign
Kalio_: <script type="text/javascript"><?php printf( "var data = %s;", json_encode($data) ); ?> for(key in data) { .... }</script>
that's the simplest way
Kalio_: AJAX is more flexible
Kalio_
ah and $data is for example the mysql data
AcidReign
yes
         

Kalio_
ahh ok wait i try it :P
AcidReign
Kalio_: and with PDO you could do: json_encode($stmt->fetchAll())
instead of having to write your own loop to read all rows
then you just write the javascript loop to process the data on the client
Cooler
i am getting an error
SSL certificate problem: unable to get local issuer certificate
when using libcurl to access a url
Kalio_
Do u have a tutorial for that?
AcidReign: Ah i Got it with the PDO...
But now how can I work with the array
geode
hellooooo :)
OP
Hellow
Is there any quick and a simple way to compile a php extension for multiple php versions
on a linux platform
geode
:) i know it is not related with php but i have a problem with an app written with php and using twig for templates.
lenswipe
hey guys
geode
i changed a twig template file for customization of footer
but now the theme is not working
Cooler
anybody?
how do you solve the SSL certificate error?
lenswipe
I'm developing a library that has plugins.....the only thing in, the plugins sort of require the meta library during development for unit testing purposes - should i add the meta library as a dev dependency?
Kalio_
AcidReign: When I create the PDO Statement and When I Get the Data with It, is it okay when I call the Java Script Function and give the data of the db to the js function?
mrtakdeniz
Hey guys
I'm using google geocode with file_get_contents
but I'm using it on an array which has 500+ value
and it returns 502
should i use cUrl?
lenswipe
mrtakdeniz, what are you trying to do?
http 502 means bad gateway
mrtakdeniz
I have city and district names, (like 500 rows) and I'm sending google geocode to get them coordinates
i'm getting districts by foreach loop, and i called geocode function inside here.
I'm using file_get_content as geocode function.
and It returned 502 bad gateway. What can I do? I think i can give a sleep on foreach, or I can use cURL to get data on function?
lenswipe
<mrtakdeniz> i'm getting districts by foreach loop, and i called geocode function inside here
no.
dont call REST APIs in a foreach loop
mrtakdeniz
lenswipe, yeah, i tought so :3
but no better way i found
lenswipe
I don't know the google geocode API but I would imagine the 502 is their way of saying "fu*k you, I'm shutting you down"
mrtakdeniz
lenswipe, exactly that was the situation
lenswipe
I would be surprised if there wasn't some way to pass multiple records across all in a oner
         

mrtakdeniz
hmm should I check the API lenswipe ?
lenswipe
this is exactly the type of thing i get onto coworkers about when they send me work to QA(i.e I aint merging it until you stop doing that sh*t)
might be a good idea.
Kalio_
I reedited the code... Can someone tell me... Is that a propper way to use php with JS? :) http://pastebin.com/X0siNFaF
lenswipe
Kalio_, the correct way would be to JSON encode the data and then use that inside javascript
AcidReign
lenswipe: exactly what I said.
lenswipe
turn that data from $statement->fetch into an array (while we're at it, database calls in a loop aren't a great idea...)
Kalio_, also - protip: gist is better than pastebin ;)
AcidReign, :)
Kalio_
lenswipe: AcidReign : ok i try it... Hm
mrtakdeniz
lenswipe, nope :\ only I found is timeout..
there is no multiple addresses part on documentation
and after google search, just found loops with timeout..
DarkChaoz
hello, how do i count the number of arrays http://pastebin.com/Qg99Jb4f
not sure how do it with this type of array
lenswipe
mrtakdeniz, im off to watch TV with my GF
good luck :)
o/
Kalio_, ^
mrtakdeniz
have a nice night ^^
DarkChaoz
hello, how do i count the number of arrays http://pastebin.com/Qg99Jb4f
not sure how do it with this type of array with count
Kalio_
Ok now I json_encode the statement and don't use a Db loop But I got an Undefined var back... Why? :D
https://gist.github.com/anonymous/cdeae8c3606aa443a439
vlt
DarkChaoz: count($the_thing_you_var_dumped) should return 5.
Kalio_
(Now on Gist)
OnceMe
can someone help me why do I get this error Parse error: syntax error, unexpected 'use'
Zeranoe
What is a decent PHP gallery? Uber, Folio, or Single File PHP Gallery?
OnceMe
I have include('../fb.php'); and inside fb.php require_once( 'fbcode/lib/Facebook/FacebookRequest.php' ); and use Facebook\FacebookRequest; and so when I try to use it in custom.php where I included fb.php, I use it like this $request = new use Facebook\FacebookRequest($fbuser, 'GET', '/me');, what am I missing?
vlt
OnceMe: A wild guess: The parser didn't expect the statement "use" here.
OnceMe
ah just to remove "use" then?
Kalio_
AcidReign: Maybe you? :D The Last time :/
DarkChaoz
@vlt it gives me an undefined offset error
<b>Notice</b>: Undefined offset: 5 in <test.xml.php</b> on line <b>482</b><br />
wait nvm.. its not even counting nothing at all
wfpkhc
would it be considered bad practice to initialise a class inside another class?
tw2113
wfpkhc, it does hardcode the class inside the other class, making the code less flexible
wfpkhc
but its not passed in as a constructor
tw2113
that'd be the better route, pass it in via dependency injection
wfpkhc
but its not - its done with a new inside the method
the reason why i am asking is because - there are 10 objects needed, which have methods of "save", "update" etc - and I want to do thsoe 10 objects in a specific order, so I am thinking of a class, which creates these objects and then does them in the order, - but only calling the containg class when needed - does that make sense?
tw2113
sounds like it's pretty complex
wfpkhc
ill explain it then - you have a class (procedure class, do things in a certain order) you have 10 classes which model something, and the procedure class just does those objects in the order you want
p4trix
Why not have a method/function which does that job? Sounds pretty much like a controller action
tw2113
just to clear my confusion, are you passing objects via new Something( $someobject ) ?
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 next »