I was woundering about PHP and JavaScript.
If you wan't to develop a PHP and JS game the game itself should be in JS and the Backend PHP to call the MySQL and Query?
I'm very confuser on how to use PHP and JS together, answering this will make it sooo much clearer.
Just a quick question to clear up my confusion.
Just a quick question to clear up my confusion.
Here take a bad computer/programming-thingy joke:
"The best thing about UDP jokes is that I don’t care if you get them or not."
"The best thing about UDP jokes is that I don’t care if you get them or not."
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Just a quick question to clear up my confusion.
To understand how they work together, you need to know exactly what each one is (both have more uses than this, but for simplicity's sake, I am only going to mention the main ways that 99.99% of users use them). PHP is a server-side scripting language. The end-user never gets the PHP sent to them. It is executed on the web server which generates HTML that is sent to the client. Javascript, on the other hand, is a client-side scripting language. It does nothing at all on the server, and only acts when it is sent to the end-user. It is used for making dynamic things happen on the webpage without page refreshes (which PHP cannot do, since PHP has to hit the server for every update). Javascript can be written right in to a PHP file, and the PHP interpreter on the web server will resolve the PHP code and send the resulting HTML, including your Javascript code, to the end-user where the JS will run in their browser. That is how Javascript and PHP live in harmony side-by-side.
Now to make them actually work together is a bit more complicated, and that makes up the techniques of AJAX. AJAX is where you write your Javascript so that it can make a connection back to the web server, call server-side scripts (PHP in this case), get results back to the browser, and update the end-user's web page using Javascript, all without a page refresh.
Does this clear things up a bit?
Now to make them actually work together is a bit more complicated, and that makes up the techniques of AJAX. AJAX is where you write your Javascript so that it can make a connection back to the web server, call server-side scripts (PHP in this case), get results back to the browser, and update the end-user's web page using Javascript, all without a page refresh.
Does this clear things up a bit?
The indelible lord of tl;dr
Re: Just a quick question to clear up my confusion.
Fully agree with jack here .
Jack that does clear a lot up really .well from what i read about it.
Jack that does clear a lot up really .well from what i read about it.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Just a quick question to clear up my confusion.
yep Jack has it perfect.
It is like painting a paint by numbers board.
Think of it like a MySQL as a cabinet full of paint. It has all the colors in tubes all lined up on the bins. You use PHP to grab a tube and place it on the table in a holder(variable). Javascript is your paintbrush and CSS is your paper, all divided into sections with numbers. You take your paintbrush to grab some color so now even though you have paint still in the holder you also have some on your brush which is another variable. You can now take your paint and apply it to the canvas and the numbers tell you where to paint.
So while the paint came from mysql it was applied with javascript using PHP to bring it to the table.
It is like painting a paint by numbers board.
Think of it like a MySQL as a cabinet full of paint. It has all the colors in tubes all lined up on the bins. You use PHP to grab a tube and place it on the table in a holder(variable). Javascript is your paintbrush and CSS is your paper, all divided into sections with numbers. You take your paintbrush to grab some color so now even though you have paint still in the holder you also have some on your brush which is another variable. You can now take your paint and apply it to the canvas and the numbers tell you where to paint.
So while the paint came from mysql it was applied with javascript using PHP to bring it to the table.
Re: Just a quick question to clear up my confusion.
Well Jack thank you for clearing it up a bit, it was hard to understand att fist since English is not my main language BUT after i read it through a cuple of times i think i got the jist of it.
But i have a follow upp Question:
1) Is it impossible to use JS with PHP without the use of AJAX?
2)This is aimed for Hallsofvallhalla: Are we going to see some video tutorials on JS with PHP?
But i have a follow upp Question:
1) Is it impossible to use JS with PHP without the use of AJAX?
2)This is aimed for Hallsofvallhalla: Are we going to see some video tutorials on JS with PHP?
Here take a bad computer/programming-thingy joke:
"The best thing about UDP jokes is that I don’t care if you get them or not."
"The best thing about UDP jokes is that I don’t care if you get them or not."
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Just a quick question to clear up my confusion.
I'm sorry for being irretating xD
I'm kinda new to all this, trying to learn JavaScript ( Lucky for me it's kinda lika C++ )
I'm a bit obsessed with optimising my pages, so here is a question:
Should i use JavaScript to validate in Login and Registering page then send the final data to PHP wich register it to the DB?
This way you wont need to strain the server OR reload the page everytime you have done something wrong.
Or would you consider this just overkill?
EDIT:
Ignore the Loging screeen, since you need to query the DB anyways each time you try to loging( To se if the username and password exists ) their is really no need for JavaScript, is their?
But still, validating with JS then sending the final Data too PHP? This way the server don't need to check all the incoming data( Just security checks ) wich should strain the server less each time someone forgot to fill in a field.
I'm kinda new to all this, trying to learn JavaScript ( Lucky for me it's kinda lika C++ )
I'm a bit obsessed with optimising my pages, so here is a question:
Should i use JavaScript to validate in Login and Registering page then send the final data to PHP wich register it to the DB?
This way you wont need to strain the server OR reload the page everytime you have done something wrong.
Or would you consider this just overkill?
EDIT:
Ignore the Loging screeen, since you need to query the DB anyways each time you try to loging( To se if the username and password exists ) their is really no need for JavaScript, is their?
But still, validating with JS then sending the final Data too PHP? This way the server don't need to check all the incoming data( Just security checks ) wich should strain the server less each time someone forgot to fill in a field.
Here take a bad computer/programming-thingy joke:
"The best thing about UDP jokes is that I don’t care if you get them or not."
"The best thing about UDP jokes is that I don’t care if you get them or not."
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Just a quick question to clear up my confusion.
Yes do all your error checking first. Accessing the DB should done only after everything else has been checked, also you could have it access limited fields to keep the request lighter.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Just a quick question to clear up my confusion.
That is where AJAX comes into play. Have you ever signed up for a F2P MMO, or some other service, and after you type in the username you want the page immediately shows a message saying "This username is not available" before you submit the page? Uses like this and search box suggestions (like on the main google search page or on Amazon) are among the most common uses for AJAX, and they are very beneficial.Qunox wrote:EDIT:
Ignore the Loging screeen, since you need to query the DB anyways each time you try to loging( To se if the username and password exists ) their is really no need for JavaScript, is their?
The indelible lord of tl;dr
Re: Just a quick question to clear up my confusion.
That is correct, when the user register i wan't to be able to validate all the information with JavaScript(Since it's client sided it will be faster than reloading the whole page.)
Problem is i can get it to work but only with the alert(); function. If i try a document.write() the Error text is only shown.
My goal is to Show Error text AND the form.
I was thinking all wrong in the begining, i was checking in the <body> if their was any error messages from the function in the <head>
Problem is, if i want to do that the page must be reloaded xD and that was my first goal not to make the user reload the page ALL the time.
So anyone knows a good solution? Since JS is used for dynamic webpages, right?
EDIT:
Jackolantern: Should i use AJAX to validate register and loging page?
Using PHP to validate it all but with the use of AJAX? This way it still needs to connect to the server everytime BUT the user wont need to reload all the time.?
Problem is i can get it to work but only with the alert(); function. If i try a document.write() the Error text is only shown.
My goal is to Show Error text AND the form.
I was thinking all wrong in the begining, i was checking in the <body> if their was any error messages from the function in the <head>
Problem is, if i want to do that the page must be reloaded xD and that was my first goal not to make the user reload the page ALL the time.
So anyone knows a good solution? Since JS is used for dynamic webpages, right?
EDIT:
Jackolantern: Should i use AJAX to validate register and loging page?
Using PHP to validate it all but with the use of AJAX? This way it still needs to connect to the server everytime BUT the user wont need to reload all the time.?
Here take a bad computer/programming-thingy joke:
"The best thing about UDP jokes is that I don’t care if you get them or not."
"The best thing about UDP jokes is that I don’t care if you get them or not."