Please login or register.

Login with username, password and session length
Advanced search  

News:

We are constantly trying to improve phpfreaks and these forums, so feel free to go to the PHPFreaks Comments/Suggestions board and point out anything you'd like to see different!

Maintenance Notice

PHPFreaks has successfully moved to a new Dedicated Server, hosted by Server Powered. Please help support future upgrades by Donating.

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

0 Members and 1 Guest are viewing this topic.

paulmo

  • Enthusiast
  • Offline Offline
  • Posts: 74
    • 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!!
Logged

ProjectFear

  • Addict
  • Offline Offline
  • Gender: Male
  • Posts: 2,633
    • View Profile
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.
Logged

I help because I enjoy helping others. But please help me (and others) by posting understandable questions! Oh and use the CODE tags.

-------------------------------------------------

Daring ideas... They are like chessmen when moved forward. They may be beaten, but they may start a winning game...

paulmo

  • Enthusiast
  • Offline Offline
  • Posts: 74
    • 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!!
Logged

ProjectFear

  • Addict
  • Offline Offline
  • Gender: Male
  • Posts: 2,633
    • View Profile
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.
Logged

I help because I enjoy helping others. But please help me (and others) by posting understandable questions! Oh and use the CODE tags.

-------------------------------------------------

Daring ideas... They are like chessmen when moved forward. They may be beaten, but they may start a winning game...

Mchl

  • Supporter
  • Addict
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 2,402
  • That's Largo in my avatar, not me.
    • View Profile
    • WWW
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).
Logged

PHP 5.2.6 | MySQL 5.1.30
Input queue: sqlite, Zend Framework, PostgreSQL
NetBeans fanatic | ExtJS masochist
I'm true neutral. I go both ways.

paulmo

  • Enthusiast
  • Offline Offline
  • Posts: 74
    • 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?   

Logged

corbin

  • Guru
  • Fanatic
  • *
  • Offline Offline
  • Posts: 4,083
    • 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.
Logged

Why doesn't anyone ever say hi, hey, or whad up world?
Now I'll be uncreative, and put stats no one cares about.
Win Vista (It doesn't suck!) | Apache 2.2 | PHP 5.2 | MySQL 5 | MSSQL 2008
Fedora Core 9 | Apache 2.2 | PHP 5.2 | MySQL 5
After all, why would you insert your penis into a hole for no reason whatsoever?

Mchl

  • Supporter
  • Addict
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 2,402
  • That's Largo in my avatar, not me.
    • View Profile
    • WWW
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
Logged

PHP 5.2.6 | MySQL 5.1.30
Input queue: sqlite, Zend Framework, PostgreSQL
NetBeans fanatic | ExtJS masochist
I'm true neutral. I go both ways.

corbin

  • Guru
  • Fanatic
  • *
  • Offline Offline
  • Posts: 4,083
    • 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.
Logged

Why doesn't anyone ever say hi, hey, or whad up world?
Now I'll be uncreative, and put stats no one cares about.
Win Vista (It doesn't suck!) | Apache 2.2 | PHP 5.2 | MySQL 5 | MSSQL 2008
Fedora Core 9 | Apache 2.2 | PHP 5.2 | MySQL 5
After all, why would you insert your penis into a hole for no reason whatsoever?

Mchl

  • Supporter
  • Addict
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 2,402
  • That's Largo in my avatar, not me.
    • View Profile
    • WWW
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. ;)
Logged

PHP 5.2.6 | MySQL 5.1.30
Input queue: sqlite, Zend Framework, PostgreSQL
NetBeans fanatic | ExtJS masochist
I'm true neutral. I go both ways.

corbin

  • Guru
  • Fanatic
  • *
  • Offline Offline
  • Posts: 4,083
    • 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.)
Logged

Why doesn't anyone ever say hi, hey, or whad up world?
Now I'll be uncreative, and put stats no one cares about.
Win Vista (It doesn't suck!) | Apache 2.2 | PHP 5.2 | MySQL 5 | MSSQL 2008
Fedora Core 9 | Apache 2.2 | PHP 5.2 | MySQL 5
After all, why would you insert your penis into a hole for no reason whatsoever?

paulmo

  • Enthusiast
  • Offline Offline
  • Posts: 74
    • 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.
Logged

paulmo

  • Enthusiast
  • Offline Offline
  • Posts: 74
    • 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
Logged

paulmo

  • Enthusiast
  • Offline Offline
  • Posts: 74
    • 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.
Logged
Pages: [1]
 

Page created in 0.069 seconds with 19 queries.