Author Topic: php vs. javascript tasks? framework or no?  (Read 1786 times)

0 Members and 1 Guest are viewing this topic.

Offline paulmoTopic starter

  • Enthusiast
  • Posts: 137
    • View Profile
php vs. javascript tasks? framework or no?
« on: November 21, 2008, 11:18:20 PM »
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!!

Offline Jaysonic

  • Fanatic
  • Posts: 3,332
  • Gender: Male
  • 8548863
    • View Profile
    • I Am Lewy Babes
Re: php vs. javascript tasks? framework or no?
« Reply #1 on: November 21, 2008, 11:21:44 PM »
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.
Good luck with your coding.
Jason ~ ProjectFear ~ Jaysonic (and variations of... :))

Offline paulmoTopic starter

  • Enthusiast
  • Posts: 137
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #2 on: November 22, 2008, 07:58:07 AM »
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!!

Offline Jaysonic

  • Fanatic
  • Posts: 3,332
  • Gender: Male
  • 8548863
    • View Profile
    • I Am Lewy Babes
Re: php vs. javascript tasks? framework or no?
« Reply #3 on: November 22, 2008, 08:14:00 AM »
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.
Good luck with your coding.
Jason ~ ProjectFear ~ Jaysonic (and variations of... :))

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: php vs. javascript tasks? framework or no?
« Reply #4 on: November 22, 2008, 09:08:21 AM »
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).
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline paulmoTopic starter

  • Enthusiast
  • Posts: 137
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #5 on: November 22, 2008, 11:35:27 AM »
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?   


Offline corbin

  • Guru
  • Freak!
  • *
  • Posts: 7,951
  • Gender: Male
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #6 on: November 22, 2008, 11:55:11 AM »
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.
Why doesn't anyone ever say hi, hey, or whad up world?

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: php vs. javascript tasks? framework or no?
« Reply #7 on: November 22, 2008, 12:11:56 PM »
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
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline corbin

  • Guru
  • Freak!
  • *
  • Posts: 7,951
  • Gender: Male
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #8 on: November 22, 2008, 01:49:36 PM »
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.
Why doesn't anyone ever say hi, hey, or whad up world?

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: php vs. javascript tasks? framework or no?
« Reply #9 on: November 22, 2008, 02:02:41 PM »
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. ;)
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline corbin

  • Guru
  • Freak!
  • *
  • Posts: 7,951
  • Gender: Male
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #10 on: November 22, 2008, 02:22:25 PM »
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.)
Why doesn't anyone ever say hi, hey, or whad up world?

Offline paulmoTopic starter

  • Enthusiast
  • Posts: 137
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #11 on: November 22, 2008, 08:20:13 PM »
Quote
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.

Offline paulmoTopic starter

  • Enthusiast
  • Posts: 137
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #12 on: November 22, 2008, 08:46:32 PM »
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

Offline paulmoTopic starter

  • Enthusiast
  • Posts: 137
    • View Profile
Re: php vs. javascript tasks? framework or no?
« Reply #13 on: November 22, 2008, 09:09:07 PM »
please disregard question above; found instructions, treat as external file.