Jump to content

Archived

This topic is now archived and is closed to further replies.

paulmo

php vs. javascript tasks? framework or no?

Recommended Posts

pretty much a newbie with a website and some tutored php code, and mysql connection/table; reading about javascript and php frameworks, the capabilities seem very similar, so wondering:

1) can js do everything php can? interface with mysql?

2) after finishing reading php 6 and mysql (larry ullman), should i learn a couple frameworks (zend/jquery or yui) or just code from scratch?

 

this for website with text responses from forms (want to expand to more variables and use functions which i know nothing about but seem cool, and eventually call database or third party info (google etc.) which would be edited according to form response values):

www.releasecenter.org

 

thanks for advice!!

Share this post


Link to post
Share on other sites

As far as I know, JS can't connect to MySQL. That's what PHP does. You can request things from MySQL through PHP using AJAX. As for frameworks, I don't use a PHP Framework but I do use a JavaScript framework (jQuery). I only learnt the one JS framework though, thought that it would be enough.

I guess it comes down to personal preference though.

Share this post


Link to post
Share on other sites

so php for database, and js for calling files and effects? can js insert/get values into/from another file(s) acting like database tables?

 

on my site i've got js for date, capitalize first letter in name field, and third party geolocation. besides what i'm using and effects, what else is js useful for over php? 

 

from what i've read seems that js framework is a good idea and less use php framework. true?

 

thanks!!

Share this post


Link to post
Share on other sites

so php for database, and js for calling files and effects? can js insert/get values into/from another file(s) acting like database tables?

You can use AJAX to make PHP and JS communicate. Which is where you see forums that tell you if your username is already taken before you submit the form. It simply uses AJAX to send a request to a PHP file that checks the database for the username you entered, then returns a value that you can check with JS and then set an image as either a tick or a cross.

 

on my site i've got js for date, capitalize first letter in name field, and third party geolocation. besides what i'm using and effects, what else is js useful for over php? 

Well, they are hard to compare really. They are made for different things in mind. PHP acts on the server-side, so everything is done before it is displayed to the user. JS, however, is client-side. So JS can be used while the page is loaded. But JS can be disabled by the user, PHP can not.

 

from what i've read seems that js framework is a good idea and less use php framework. true?

I, and probably a lot of people, prefer JS frameworks. I don't use PHP frameworks though, its just a matter of personal preference.

Share this post


Link to post
Share on other sites

On general remember this:

 

JavaScript executes on client computer. So:

1. User has to download your code => keep your JavaScript files reasonably sized

2. User will see you code => don't put anything security related into JavaScript

3. User can modify your code => validate all data sent from browser using server-side scripts.

 

And last but not least, if you have to do some calculations, better do them in PHP. You'll get results faster (in most cases).

Share this post


Link to post
Share on other sites

thanks, those comments are helpful. think i'm getting it...javascript can be used as a supplement to enhance php forms and user experience.

 

but how about the main content? in php i've used cases, variables/values and switch statements. can these be done using javascript? or better to keep using php? 

 

 

Share this post


Link to post
Share on other sites

Just remember this:

 

 

PHP should be used to output data to the client.

 

Javascript can (not should) be used to manipulate the data sent to the client.  The PHP script should never rely on JavaScript to make its output look right.

Share this post


Link to post
Share on other sites

The PHP script should never rely on JavaScript to make its output look right.

 

Unless you can tell your users, that they have to have JavaScript enabled in their browsers, or they'll be fired... :P

Share this post


Link to post
Share on other sites

Eh yeah.... I guess I should revise my earlier statement to go something like:

 

"You should try to avoid using JavaScript to make the output look a certain way, unless your site will definitely have to depend on JS."  Then again, there are very few sites out there that can actually justify not having the site work with JS disabled.

Share this post


Link to post
Share on other sites

I posted previous message, because I'm developing an intranet application, where all GUI is JS based. But I can afford it. Since its intranet, I say what browser to use and how to configure it. It sure makes thing easier. ;)

Share this post


Link to post
Share on other sites

Yeah....

 

 

I personally thing it's fine for some sites to depend on JS.

 

For example, I don't know if facebook depends on JS or not (although I know it uses it a ton), but chances are, most people going there will have JS enabled, and if they don't, they will be willing to enable it, so they don't really have to worry about it.

 

Also, if one of the major features of a site is actually it's use of JavaScript, then it's ok too.  (Which is what it sounds like in your case.)

Share this post


Link to post
Share on other sites
PHP should be used to output data to the client.

 

Javascript can (not should) be used to manipulate the data sent to the client.  The PHP script should never rely on JavaScript to make its output look right.

 

this really puts both in perspective—thanks.

Share this post


Link to post
Share on other sites

i've downloaded jquery. it's a js file on my desktop. trying to "run." microsoft jscript runtime error, 'window' is undefined. how to do this? thanks

Share this post


Link to post
Share on other sites

please disregard question above; found instructions, treat as external file.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.