SitePoint Sponsor |
|
User Tag List
Results 26 to 49 of 49
-
Oct 1, 2006, 13:26 #26
- Join Date
- Jul 2006
- Posts
- 200
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
re: oop
In fact please read my post on this very thing. I am really looking for some example code. http://www.sitepoint.com/forums/showthread.php?t=426306
-
Oct 1, 2006, 15:00 #27
- Join Date
- Jan 2006
- Posts
- 71
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A class can be a collection of functions, therefore, you are still passing to a function whether it is in a class or not. Speaking of databases, what if you ever had to switch from Access to MS SQL? If the database items had been implemented in a class, you could easily change between database types. Not only that, but if you were a software company you could provide your software to many different database platforms with very little coding.
While providing new functionality, OOP also enhances readability. Compare a 10,000 line OOP program vs a 10,000 line functional one and you'll see a huge difference. If you ever have to read someone else's spaghetti code, you'll understand.
As far as examples to an online database, google has a pretty large one hehe. Look at Google Suggest which uses ajax and provides suggestions as you start typing in the search field:
http://www.google.com/webhp?complete=1&hl=en
Also, have you ever sold an item to ebay? They use ajax when selecting categories of an item you are trying to sell. You select from a high level category (sports), then a new dropdown is prefilled based on what you chose(football, basketball...), and then based on that dropdown, yet another dropdown is prefilled (high school, college, professional) based on what you chose there and so on.
For code examples, just google "ajax suggest" and you'll get a lot of hits.
-
Oct 1, 2006, 15:20 #28
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
An object encapsulates the methods (functions) and data within itself. Maybe this simple program (tested with PHP 4.4.1) with comments may answer the question of how classes pass data back and forth between methods (functions in procedural languages). Stepping through the code, comments and running it should clarify a few things up. Again, this is very simple, the real power, lays in creating abastract classes and polymorphism.
PHP Code:<?php
class pet {
var $pets_name;
var $preferred_food;
var $pet_type;
function pet($pets_name,$pet_type,$food_type){
$this->set_pets_name($pets_name);
$this->set_pet_type($pet_type);
$this->set_food_type($food_type);
}
function set_pets_name($newpetsname){
$this->pets_name = $newpetsname;
}
function set_pet_type($newpettype){
$this->pet_type = $newpettype;
}
function set_food_type($newfoodtype){
$this->preferred_food = $newfoodtype;
}
function show_the_pet(){
echo $this->pets_name . " is a " . $this->pet_type . " and perefers to eat " . $this->preferred_food . "\r\n";
}
}
class fish extends pet {
var $PH;
function fish($fishname,$foodtype,$PH){
// calls the inheretied pet() method to set name, pet type and food type
// to set the name of the pet and preferred food type
parent::pet($fishname,"Fish",$foodtype); // calls pet() from the pet class with 2 arguments
$this->set_PH($PH);
}
function set_PH($PH){
$this->PH = $PH;
}
function show_the_pet() {
parent::show_the_pet(); // calls the show_the_pet method from the inherited pet class which displays the pets name, type and food type
// the only thing we need to add is output about the PH
// for the fish
echo $this->pets_name . " has a PH Balance of $this->PH \r\n"; // remember pets_name is inherited from the pet class
}
}
// we create instances of a couple of pets
$cat = new pet("Puffy","Cat","9 Lives");
$dog = new pet("Bopper","Dog","Gravy Train");
// display the info about the pets
$cat->show_the_pet(); // displays "Puffy is a cat and eats 9 Lives";
$dog->show_the_pet(); // displays "Bopper is a dog and eats Gravy Train";
// Uh oh, the vet puts Bopper on a diet!
// now displays "Bopper is a dog and eats Diet Doggie Crunch";
$dog->set_food_type("Diet Doggie Crunch");
$dog->show_the_pet();
// Uh, Oh, the pet shop owner wants to add fish with a PH data field.
// Well, makes no sense to add it to pets, since a dog or cat doesn't need PH
// so, we will create a new class called fish, which inherits all the data
// fields and methods (functions) from pet, then add the PH field to the
// fish class.
// displays "Bubbles eats Sparkle Flakes" and also displays "Bubbles has a PH Balance of 1.4
$PH = "1.4";
$fish1 = new fish("Bubbles","Sparkle Flakes",$PH);
$fish1->show_the_pet();
?>intragenesis, llc professional web & graphic design
-
Oct 1, 2006, 16:08 #29
- Join Date
- Jul 2006
- Posts
- 200
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
re:oop
Don't even go there with pets. I have programmed a pedigree program that most programmers wouldn't have a clue how to program (desktop version not web). And I have programmed an access frontend to sql server and mysql. I am still learning php, and only been involved in web databases (learning) for a few months. In past it was all networked applications. So after 100,000 post, someone above answered the question: Functions are used in oop.
Read this post carefully: http://www.sitepoint.com/forums/showthread.php?t=426306 , it exlpains what I'm trying to accomplish in a web database. If oop is so good how come no one can answer the really hard questions? That google thing still don't come close to what I'm trying to do. Simply have a text box to enter a search string, i.e., wh. Hit a enter or go button and have the dropdown filled with all occurrences of wh -- white freight, whitman trucking, etc. But at the same time after selecting whitman trucking, have their phone and fax filled. And if that's not enough, have other fields -- load number, etc on this same page. Then a final submit button to send this info to database. There are shipper and receiver filds also.Now I bet the google thing don't do anything this advanced. But I am going to check anyway.
-
Oct 1, 2006, 16:25 #30
- Join Date
- Jan 2006
- Posts
- 71
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What you're asking for in that other thread is more ajax-related than it is oop. There are tons of sites out there with examples of everything you want to do.
http://www.w3schools.com/ajax/default.asp
Here's something sort of similar to what you were wanting, click on the links towards the top to expand the different samples, for instance "Drop Downs & Form Handling".
http://www.clearnova.com/ajax/
-
Oct 1, 2006, 16:38 #31
- Join Date
- Apr 2006
- Location
- Pennsylvania
- Posts
- 1,736
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by jim9
-
Oct 1, 2006, 17:00 #32
- Join Date
- Sep 2002
- Location
- Canada
- Posts
- 2,087
- Mentioned
- 1 Post(s)
- Tagged
- 1 Thread(s)
Originally Posted by jim9
"A nerd who gets contacts
and a trendy hair cut is still a nerd"
- Stephen Colbert on Apple Users
-
Oct 1, 2006, 17:21 #33
- Join Date
- Jul 2006
- Posts
- 200
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
re: Grateful
I do thank you for replying. Actually the post I referred people to is php related. I am trying to implement some ajax within php programming. If you read the post, I'm not after auto complete. I'm after something like http://www-128.ibm.com/developerwork...ro2/index.html. But instead of entering a phone number, I want to select from a dropdown.
But first narrow the dropdown results from a "enter search string box". I realize until recently this type of stuff wasn't done on the web, it's new technology. Does anyone have actual code examples I could download of this. The IBM example is close, but there is a missing link that I need to learn. I have actually worked with there example and got it working.
-
Oct 1, 2006, 17:34 #34
- Join Date
- Jan 2006
- Posts
- 71
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Post in the javascript forum and you should be able to get a response.
You just need an onchange event in the search string box to dynamically update a select menu using ajax.
-
Oct 1, 2006, 18:03 #35
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by jim9
Originally Posted by jim9
Originally Posted by jim9
Don't brag on how "great" your programming skills are for desktop applications when you are clearly wanting to learn how to write server side applications.
Were here to try and help you with your questions, I think you have been provided with more than enough to answer your questions...and if not, do a search in the forums. So, why don't you review what everyone has posted, buy a book, RTFM, and get your feet wet by actually doing some server side coding.
If you have a problem with some code, that is cool, throw the question out there and I think many folks will help you out!intragenesis, llc professional web & graphic design
-
Oct 2, 2006, 05:19 #36
- Join Date
- Jul 2006
- Posts
- 200
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
http://www.clearnova.com/ajax/ was a good example, thanks
-
Oct 2, 2006, 05:48 #37
- Join Date
- Sep 2005
- Posts
- 55
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by jim9
Originally Posted by jim9
as for this:
Originally Posted by jim9
with that attitude, 99% of the stuff we use today, that people have created and invented, would not exist.
i could go on forever:
why create the car, when we had a bike?
in this case, though;
Originally Posted by jim9
)
the thing is, common sense would tell you that if there is two options in anything, the one with more features, more mature, better tested, and has better testimonials (which you can take as pretty much everyone in this thread telling you PHP 5 is better) - you go with the best option available - in this case, PHP 5 applies.
as for the OOP argument that seemed to crop up out of nowhere (why, i dont know, as you seem to be looking for basic AJAX examples) - the argument is ancient. if you ask me, some people just simply dont have the capacity to pick it up. though people say its a paradigm shift; in some ways it is, in physical coding terms - but in psychological terms, no shift has taken place; it was always there, it just needed something to kick it into action, something to spark it off (displayed by the classic 'a-ha!' moment) - the OO way of thinking is a general principle that you can apply to life, and many people do.
however, for the unfortunate few, they will never experience this, and will happily trudge through with things 'getting by, because it works' - never striving to do better, to find a better way.
-
Oct 2, 2006, 13:25 #38
- Join Date
- Jul 2006
- Posts
- 200
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
My point is this, php4 is on most hosted servers in the world. There's already talk of a php6 coming out. Now to add 2 + 2 for you, before php5 is even out widespread there will be a php6. My point is exactly that, they aren't even going to let the php5 you like so much become an aldult. Use your brain, I don't mean never come up with new stuff, but good grief, let it have a life before you replace it. I would probably like php5 if it was more backwards compatable to php4. Case in point:Microsoft is real bad about that. They were coming up with new versions of access just when the current version became stabe with all the updates. But do you realize how many developers still develop in one of the older versions due to stability? Man let's progress, but let's enjoy and take a breath along the way. The way you sound, you'd build a house, live in it a week, tear it down for a bigger upgrade. Me, I'd at least live in the house for a few years first.
-
Oct 2, 2006, 13:35 #39
Originally Posted by jim9
-
Oct 2, 2006, 14:24 #40
- Join Date
- Apr 2006
- Location
- Pennsylvania
- Posts
- 1,736
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Also, the timeframe between PHP4 and PHP5, I believe, was the largest time difference of any two previous PHP versions. PHP/FI in 1995; PHP/FI 2 in 1997; PHP 3 in 1998, PHP 4 in 2000, PHP 5 in 2004. From the start, PHP seems to have had a tendency to release a major version every 2 years or so. Further, 2 years (how long PHP5 has been out) is plenty of time for people to migrate, IMNSHO.
-
Oct 2, 2006, 15:36 #41
PHP 5 all the way.
-
Oct 4, 2006, 17:48 #42
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi...
Originally Posted by jim9
.
Originally Posted by jim9
What do you think polymorphism is?
Originally Posted by jim9
You are obviously not going to make the effort to learn OO until you see a need. While you are slapping front ends on relational data, you won't. Fair enough.
You might start to see the point when you are dealing with non-tabular data, fuzzy data, or any system that has to evolve, or is poorly defined to begin with, a project with a large number of developers or one that has to be very flexible or configurable. That's normally anything that's new.
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Oct 4, 2006, 21:09 #43
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by rockit
jim9 does have a good point. most hosting companies, even large companies, are still running php4. The only companies I really see running (and supporting) PHP 5 are those with pricey, dedicated servers, or $el-Cheap-O companies reselling, resold, refried, resold, then resold again beaner hosting plans at those notorious great $4.95/month rates -- with the buzz word "PHP5 installed."
I run php5 on my local machine for development, but, before launch, I fire the sites up under php4 to make sure my code still runs under php4. I do a lot of OOP programming with PHP, but, at the moment I make sure that I don't code PHP5 specific.
In regards to PHP 6, again, jim9 brought up a good argument -- php5 has not been fully adopted across the web, php 4 is still the major installed version. If it weren't, we would be knocking php5 and talking about php6 and you would have to really dig through old threads for info on php4 specifics.intragenesis, llc professional web & graphic design
-
Oct 4, 2006, 21:20 #44
- Join Date
- Sep 2002
- Location
- Canada
- Posts
- 2,087
- Mentioned
- 1 Post(s)
- Tagged
- 1 Thread(s)
Originally Posted by holmescreek
"A nerd who gets contacts
and a trendy hair cut is still a nerd"
- Stephen Colbert on Apple Users
-
Oct 4, 2006, 21:53 #45
Originally Posted by holmescreek
All it takes is a few moments and your favorite search engine to realize that PHP 5 hosts are no longer a rarity. And every day more and more hosts are upgrading to PHP 5.
It is true that there are more PHP 4 hosts than PHP 5 hosts, but it is just simply not true that PHP 5 hosts don't exist or are hard to find. Just not true.
-
Oct 4, 2006, 22:17 #46
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by The New Guy
I only need one. It took several years of dealing with "big-name" hosting companies, (10 years to be exact), going from what the hosting reviews said was the best, etc, etc, to finally get to a company that I've actually been with for about 3 years. Before that, I've dealt with a lot of companies that start off with great support -- but, when things "break" -- crap support, no support answer, tech support with no phone number, and the infamous "fill out a ticket."
It is good to see competition blooming, the industry is now reaching a point where they are learning how to keep customers; they have to answer the phone 24/7, without a 45 minute que, without having to go through level 1, 2, 3 support talking to someone in India with a thick accent -- then finally transferring your call back to the US to talk to "top level" support -- where finally you can describe the problem and its fixed in about two minutes.
So, I agree -- somewhat, I don't think its the companies that follow technology, because as you can see, beyond the long distance call, the 3 step ticket system, talking to Ali-Babbi in India, then having your phone call finally transferred back to the US when you can ask the question and get the answer in 2 minutes or less -- great technology <not> --intragenesis, llc professional web & graphic design
-
Oct 4, 2006, 22:27 #47
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dreamscape
Just saying its hard enough to find a good host period -- and to find a good host that fully supports PHP5 is even harder.
WHen I state "good" host, it means that I've got 80+ clients that rely on my company to keep their small business to fortune 1000 company online. Clients that rely on my judgment to determine the hosting company that is reliable.intragenesis, llc professional web & graphic design
-
Oct 5, 2006, 05:44 #48
- Join Date
- Sep 2002
- Location
- Canada
- Posts
- 2,087
- Mentioned
- 1 Post(s)
- Tagged
- 1 Thread(s)
If you have 80+ clients its time to stop buying shared hosting and get a dedicated server and start putting on whatever you damn well please
"A nerd who gets contacts
and a trendy hair cut is still a nerd"
- Stephen Colbert on Apple Users
-
Oct 5, 2006, 07:46 #49
for me the same concept. Php4 and php 4 hoster....more reliable for my clients!
Bookmarks