Programming Languages: PHP vs JavaScript

Gyan9, go to my Board, where I am currently on Part 2 of a tutorial on a complete open-source PHP app I wrote, which is a Recipe database. Using PHP, MySQL, and Apache of course, I am currently trying to teach people how to set up all the programs, do the initial brainstorming and design, create the database, access it and insert/edit/delete/etc., handle usernames and passwords, etc. The entire project I have made open source so if I actually did something good, people can learn from it. I’m not going to post a direct link here, but if you go to the UnaBoard and then to the “Batteries Not Included” forum, you should see two threads that talk about the project. And you can see the 1.0 version of the project in full working order from a link there and a few other places on my board.

Hey, it’s a small program (well, OK, more than 100kb of PHP code, maybe not so small), but it does all the basic functions for anyone who wants to know how to interface PHP and databases and websites online for dynamic content.

The project is open-source but not public domain. The “Copyright” link from the project page explains more.

Una

BTW, the threads are:

“Making a Web-Accessible Database Program from Scratch”

and

“Making a Web-Accessible Database Program Part 2”

in the “Batteries Not Included” forum. The link to the project is halfway down page 2 of the first thread. And it’s in another forum, “Jungle Bells” (don’t ask…) in the thread “Recipe Database for Testing”.

Sorry for no direct links. I don’t want links on here.

Fierra has been looking for a new job and trying to find positions that would call out PHP, since she now has a bit of experience working with PHP and SQL. We have had great difficulty finding any, but she has numerous job positions in her folder that say “Javascript”, “Java”, or “Servlets”. So my estimate wasn’t really scientific, even if it might have reflected accuracy.

Referring to the 7th posting (Achernar’s first posting), how do I set up a loop (with count as the increment for instance) to refer to the output form:
document.dropbox.z1.value=(k/mn[sv])*s
sv=sv+1;

as

document.dropbox.count.value=(k/mn[sv])*s
sv=sv+1;
I know I could set up a 50 element array whereby the elements have values z1, z1a, etc all the way to z25a.
My problem is does JavaScript recognize array variables when you are using them to reference a specific form element?

I think this would explain why I did not do that in the first place.

If you think that’s the only use of “computerese,” you’re dead wrong. You’ve basically come in here saying, “don’t be tryin’ to snow me with none o that book-learnin’” by implying that anyone using such hi-falutin’ terms as “client-side” is just trying to look smart. That’s ignorant and offensive, and it’s not the best way to get advice from the experts.

(And for what it’s worth, if you can’t deal with the three examples of “computerese” you mentioned in your OP, you’re not going to have a very productive discussion of programming languages. It’s a bit like saying, “listen, I don’t care about all these fancy terms like ‘carburetor’ or ‘distributor’…I just want to know what kind of engine is easiest to work on.”)

To answer your other question, you’d want to do something like this:



for(var i=1; i<=25; i++)
{
    document.dropbox["z" + i].value = (k/mn[sv])*s;
    sv += 1;
    document.dropbox["z" + i + "a"].value = mn[sv];
    sv += 2;
}


That assumes there is necessarily always a pattern to the naming of the items. If not, you could do something like this:



var items = [ "z1", "z2", "x3", "rutabaga", "d23", "etc" ];
for(var i=0; i<items.length; i++)
{
    document.dropbox[items*].value = (k/mn[sv])*s;
    sv += 1;
    document.dropbox[items* + "a"].value = mn[sv];
    sv += 2;
}


(which obviously still assumes that each item has a corresponding “a” item. Tweak the code to your liking.)

This takes advantage of the fact that for a given object, you can access a property by using the [“propertyname”] notation rather than .propertyname, which allows you to have the property name stored in a string calculated at runtime. Thus (for example) document.dropbox is exactly the same as document[“dropbox”] or even document[foo] where foo is a variable containing the string “dropbox”.

Ah, minor nitpick, but if you are hard-pressed to decide between PHP and JavaScript, I suggest learning HTML first.

Your source code needs some serious work.

Duckster
Well I don’t mind construtive criticism.
I’m familiar enough with HTML to write webpages but is there anything specific you want to reference at my website?
Achernar brought up a good point so by all means point out my HTML mistakes. (seriously).
And Duckster, I thought I knew JavaScript.

Well, I’m not Duckster, but a quick overview (and I’m trying to limit myself to things that would break browsers, and not coding preferences):
The <font> tag is depreciated, and should have a </font> closing tag.
The <center> tag is also depreciated.
You have tags like <p><br> and <caption></caption> (with no text in the caption tags).
You have <tr> and <td> tags without closing tags.
You have <b> tags that (if they are closed) are closed outside other tags.
You have a <p> tag in between </tr> and <tr> tags, which is irregular to say the least.

Note that this is pure mechanical stuff, and just a 2 minute lookover. An HTML checker could probably nail down any real issues.

I note that this was written in 1999, which would explain the depreciated tags. However, the closing tags may prove to be an issue, depending on the browser used.

As a (very recently ex-) leader of an Internet Server Side software team (7 people, creating infrastructure and applications for a telco providing Cellular Internet content), I thnk PHP is possibly the BEST programming language it has been my pleasure to use (and I go back to FORTRAN).

In a sense, it is almost an “interpreted C” - which is my favorite complied language. More in terms of syntax than usage, of course - C is far lower level, and thus far more efficient at OS resource manipulation - but PHP makes me, as a “C” programmer, feel at home doing low-level web programming.

I’m not sure how well it works for people who prefer using code-wizards - I’m very much a “write it out by hand” type - but the results are, IMHO, outstanding - good, tight, efficient, error free, readable code, that dan do some quite complicated logical and procedural tasks (number and string manipulation galore, easy DB connectivity, XML parsing…) I also love the ability to import static HTML code, leave it as is, and just insert PHP code snippets at selected points to “dynamicize” it.

Pragmatically, in the sense of “what are good skills to have”, PHP also seems to be making inroads from the “early adopters” crowd into the “early majority” group, so it is possibly just about to become very big, very fast.

Dani

wolf_meister, notwithstanding magog’s comments, but your pages lack a Doc-Type for starters. Without it, a page will not render correctly in a browser, let alone meet any web standards. Another is a hodge-podge of upper- and lower-case for HTML tags. Go with one form or the other but don’t mix (and if you use an XHTML Doc-Type, tags must be lower-case).

Also, your tag attributes are sometimes in quotes and otherwise not. Web standards says all attributes are in quotes.

You mean deprecated. You used the wrong word three times, so I assume it’s not just a typo.

Well thanks to ALL for a lively discussion.
If nothing else, I guess PHP is well worth learning.
As for my HTML “skills”, well the website was written 100% in Notepad. Except for lines and backgrounds, all graphics were made with MS Paint. (Okay, I’m a cheapskate !!). Basically, if it displays properly on IE with no errors, then I’m happy. (And with all modesty aside, a lot of those calculators are listed as #1 on Google.)

ntucker - thanks for taking the time to write that JavaScript routine. Also, I am sorry if I sounded too much like a “John Wayne yer book-learning won’t do ya no good” type. Did you read what I said about the “contextually-guided merchandise experience”? I am not against progress or technical terms - sometimes it gets out of hand though. Quite recently, someone was here to fix my furnace and he asked if the “thermostat was calling”. So, I said “you mean is it ON?” Yeah, that’s what he meant. When cable installers were here many years ago, they said something “profound” like 'we lost 3 db’s going from the pole to the house". So, I said “Doesn’t that happen EVERY time you go from the pole to the house”? and they said - “well yeah”.

Okay, and again thanks to everyone for ALL the advice and suggestions. I thought this thread would get 2 or 3 responses - but the Message Board “Dopers” sure came through. I’d like to type more but my “thermostat is calling”. LOL
Thanks

Don’t feel bad about that at all. Most of the really good coders I know use plain text editors for everything (okay, maybe a little more functional than Notepad) and almost all of the really bad code and HTML I see was generated with some high-dollar GUI design tool. Keep working in Notepad or grab a freeware/shareware editor with more functionality (if you really want to see a holy war, ask which one of those is best) and use one of the free online validators like the one at W3C to check your work. A validator will pick up all those unclosed tags and make your pages compatible with a lot of the more restrictive browsers in a few easy edits.

It looks like you’ve got good Javascript skills (which I define as being able to accomplish what you need, not necessarily hitting the very best design which won’t draw any critique from a board full of experts). It should be easy for you to pick up PHP as yet another tool for making the pages you want to make. One advantage to writing your kind of calculators in PHP is that it allows you to hide the code on the server, but every calculation requires a round-trip to the server so it wouldn’t be as responsive as your client-side code.

Looking at what you’ve built, you might consider Java to be an asset as well. You could port the converter code you’ve got to compiled Java fairly easily. The GUI elements would be completely different than the HTML/Javascript version, but the guts of the calculations would port fairly easily from JavaScript to Java because they share a lot of syntax similarities. Starting from scratch on Java might be tough, but most tutorials include some sort of calculator as an example of how to build a GUI, so you could go from there and extend a basic template for all your different designs. This would allow you to provide them as either applets (loaded in a webpage), Webstart applications (which install fairly seamlessly on the client if the client has Java installed) or regular desktop apps. Your users might find this very beneficial if they’re using your converters as much as your hit count indicates. I know this is completely off-topic for what you asked and I risk starting another holy war by even suggesting it…

Sorry if I came off critically before, wolf_meister. I really do like your site.

And I use Notepad too. :slight_smile:

micco and Achernar
Thanks for posting additional comments.
Achernar, I didn’t think what you said was very critical at all. (A lot of the other posters were much more critical and some even started crticizing each other). Of course that’s to be expected on a Message Board such as this. This is perhaps the most serious Message Board on the Internet with some rather intelligent people as its members.
Anyway, Achernar, thanks for the praise about my website.

That sounds like marketing-ese rather than computerese to me.

Martin Wolf
Yes, that does sound more like marketing-ese but since it was said by a web designer, I was just considering the source.

ntucker
Please go to the new and improved Ultra Converter.
www.1728.com/convert.htm
I appreciate your taking the time to write the routine:

document.dropbox[“z” + i + “a”].value = mn[sv];
sv += 2;

That is something I orginally attempted to do when I wrote it many years ago. Now I see where I failed. Instead of what you typed, I attempted:
document.dropbox**.**[“z” + i + “a”].value = mn[sv];
sv += 2;

That’s right - that one period made it fail and so I was forced to reference the output boxes one by one. One little period. Good old JavaScript - “ARRRRRRRGGGGGGGGHHHHHH!!!”

Thanks to all for your input.