473,232 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

Classes, don't follow.

Ok I have read alot of things on zend.com, php.net and other sites went
to the wikibooks to try to understand how to use a class. I have this
project I want to do that I am sure would work great with a class. I
just don't grasp the whole concept, and how to do it.

I want to make a Collectable Card Game Draft Engine...(if any of you
play VS System, LOTR, Magic: The Gathering, you know what I am talking
about.)

It would be way to complicated for just typing in regular functions and
calling em.

So this is what I've seen That I don't understand.

Say i have a database with cards that are common(c), uncommon(u),
rare(r) from 3 sets alpha(a), beta(b), unlimited(u).

I need to 1st create 24 packs that contain 11commons, 3uncommons, and
1rare each.

Bam thats a class.

would it look like this?
Class CreateDraft{
var $set;
var $rarity;
function SelectRandomCard{
//connect to database in file header
//
$querycardbase = "SELECT * FROM `mtg_base` WHERE rarity = $rarity
AND set = $set LIMIT $rarity_num";//rarity and rarity_num are related
c=11,u=3,r=1, set dictates cards available.
$querycardbase_result6 = @mysql_query ($querycardbase);
while ($cardbaserow = @mysql_fetch_array ($querycardbase_result)) {

$packarr = $cardbaserow[card_id]
}
function InsertPack{
$insertpack = "SQL STATEMENT INSERTING AN ARRAY";//I know, i know
its late and I just want to understand.
}
}

I guess I am asking for help.. Because I do not understand.

Oct 5 '05 #1
16 2155
First, PHP4 and PHP5 have different implementations of object oriented
functionality. Being an optimist, I am going to assume you use PHP5.
Please correct me if you are using PHP4.

What I see in your story is:
- You have sets and packs of cards. This may be just an array of card
objects, or a collection class.
- You have a "generic" card object and special implementations of it.
This suggests that the generic card is abstract, and the special(common,
uncommon, rare) cards are extensions to that. But only if they BEHAVE
differently (have extra methods or different implementations of some
methods).

Best regards

Jace Benson wrote:
Ok I have read alot of things on zend.com, php.net and other sites went
to the wikibooks to try to understand how to use a class. I have this
project I want to do that I am sure would work great with a class. I
just don't grasp the whole concept, and how to do it.

I want to make a Collectable Card Game Draft Engine...(if any of you
play VS System, LOTR, Magic: The Gathering, you know what I am talking
about.)

It would be way to complicated for just typing in regular functions and
calling em.

So this is what I've seen That I don't understand.

Say i have a database with cards that are common(c), uncommon(u),
rare(r) from 3 sets alpha(a), beta(b), unlimited(u).

I need to 1st create 24 packs that contain 11commons, 3uncommons, and
1rare each.

Bam thats a class.

would it look like this?
Class CreateDraft{
var $set;
var $rarity;
function SelectRandomCard{
//connect to database in file header
//
$querycardbase = "SELECT * FROM `mtg_base` WHERE rarity = $rarity
AND set = $set LIMIT $rarity_num";//rarity and rarity_num are related
c=11,u=3,r=1, set dictates cards available.
$querycardbase_result6 = @mysql_query ($querycardbase);
while ($cardbaserow = @mysql_fetch_array ($querycardbase_result)) {

$packarr = $cardbaserow[card_id]
}
function InsertPack{
$insertpack = "SQL STATEMENT INSERTING AN ARRAY";//I know, i know
its late and I just want to understand.
}
}

I guess I am asking for help.. Because I do not understand.

Oct 5 '05 #2
You're not exactly explaining what the problem is, and I have not a lot
of experience with PHP classes, but at first glance the
SelectRandomCard function is not so random. It will always return the
same decks for a given $set. Besides, your $packarr variable will
probably not work as an array, more like a simple variable being
overwritten every time through the loop.

Hope that helps. Anyway, it would help if you could point us at more
specific problems :-)

Oct 5 '05 #3
Jace Benson wrote:
Ok I have read alot of things on zend.com, php.net and other sites went
to the wikibooks to try to understand how to use a class. I have this
project I want to do that I am sure would work great with a class. I
just don't grasp the whole concept, and how to do it.


Think of a class as a container for data and methods (functions)
which operate on that data. Here's something that might look like
classes for a deck of cards:

<?php

class Card {
var $suit;
var $value;

function Card() {

// somehow initializes a card
$this->suit = "spades";
$this->value = "10";
}

function display() {
echo "Hello, I am a " . $this->value . " of " . $this->suit ."\n";
}
}
class Deck {
var $cards = array(); // cards are stored here
var $size = 52; // 52 normal, 5
var $jokers = false; // boolean: if yes, adds 2 to deck size

function Deck() {

if ($this->jokers) {
$this->size += 2;
}

// eg. add "empty" cards to deck
for ($i=0; $i < $this->size; $i++) {
$this->cards[] =& new Card();
}
}

function shuffle() {
// some kind of function to reshuffle
$this->cards = array_reverse($this->cards);
}

function display() {
// displays the entire deck
foreach ($this->cards as $card) {
$card->display();
}
}
}
// Ok, so now that we have defined our classes, we can play some cards:

$d = new Deck();
$d->shuffle();
$d->display();
?>

And our script will output (in case above), 52 lines of: "Hello, I am
a 10 of spades".

/Marcin
Oct 5 '05 #4
Jace Benson wrote:
Ok I have read alot of things on zend.com, php.net and other sites went
to the wikibooks to try to understand how to use a class. I have this
project I want to do that I am sure would work great with a class. I
just don't grasp the whole concept, and how to do it.

I want to make a Collectable Card Game Draft Engine...(if any of you
play VS System, LOTR, Magic: The Gathering, you know what I am talking
about.)

It would be way to complicated for just typing in regular functions and
calling em.

So this is what I've seen That I don't understand.

Say i have a database with cards that are common(c), uncommon(u),
rare(r) from 3 sets alpha(a), beta(b), unlimited(u).

I need to 1st create 24 packs that contain 11commons, 3uncommons, and
1rare each.

Bam thats a class.

would it look like this?
Class CreateDraft{
var $set;
var $rarity;
function SelectRandomCard{
//connect to database in file header
//
$querycardbase = "SELECT * FROM `mtg_base` WHERE rarity = $rarity
AND set = $set LIMIT $rarity_num";//rarity and rarity_num are related
c=11,u=3,r=1, set dictates cards available.
$querycardbase_result6 = @mysql_query ($querycardbase);
while ($cardbaserow = @mysql_fetch_array ($querycardbase_result)) {

$packarr = $cardbaserow[card_id]
}
function InsertPack{
$insertpack = "SQL STATEMENT INSERTING AN ARRAY";//I know, i know
its late and I just want to understand.
}
}

I guess I am asking for help.. Because I do not understand.


I don't understand in detail what you're trying to do, but if you have a
class called 'Create<anything>', the chances are you've not understood
classes.

A class (or rather, an object of a particular class) represents a thing
- in your application probably a pack of cards, maybe an individual
card, maybe a set (alpha, beta), maybe a rarity (though that might be a
single value, in which case there's probably no point in having a class
for it).

Create would then be a method (function belonging to a class) - perhaps
the constructor that every class must have, perhaps a different method.

If you declare a function inside a class as you have for
SelectRandomCard, it is a method, so when it is called it will be called
to operate on a particular object (instance of the class), and you need
to refer to the properties of the particular object with the 'this'
pointer: $this->rarity.

Don't use classes because you think they're cool: use them if you're
prepared to think of your program in terms of creating and operating on
objects (that know how they should be operated on).

I now usually approach any programming question in terms of objects, but
it did take some work to get there!

Colin
Oct 5 '05 #5
Hi Jace,

If you are used to procedural programming OOP can be hard to grasp in
the beginning. The problem is that you see your computer as a single
entity with a single processor and memory space. Your procedural program
is essentially a list of instructions for this processor, referring to
variables in this memory. You need to let go of that idea. Objects are
more like the those beasts/puppets that run across your screen in a
computer game like boulderdash: a whole bunch of entities that seem to
live inside your computer, each doing its own things, remembering for
itself what happend and what it is doing in its own private memory
space, and interacting with one another.

With OOP, objects are things you can call methods on. If you call a
method on an object, the object may do somthing. It may also remember
somthing. What is does may depend on the things it has previously
remembered. It is like a little home computer: you can type a command,
it will print a reaction (or trigger an error if it does not know the
command). You don't need to know how it works internally. You just need
to know what will happen for each command.

But there's more. Objects are networked. When you call a method on one
object, it may ask other objects to do things by calling more methods on
them. If you call a function in procedural programming, you know what
code will be executed. If you call a method on an object, you don't,
unless you know what object you are calling the method on. But for
making the method call you will probably use a variable in which you
have put a reference to the object. So if at some point your code puts a
different object in that variable, all method calls on that object may
end up executing different code... Yes, object references are much like
function pointers. Those objects can hold other objects in their member
variables and make more method calls on those objects, and so on. This
easily leads to a magnitude of spaghetty you can not even dream of with
procedural code, even if you are using GOTO's! This spaghetty even
changes dynamicly as the program changes the contents of variables! New
objects may be created. References to objects may be returned and stored
.. AARCH!

This is what classes are made for: To create some structure in the
object spaghetty. Firs we classify all objects. Then we only define
methods in the classes. So if you have a variable referencing an object,
and you know the class of the object in advance, you know what code will
be executed if you call a method on that object. Becuase most
programmers somehow tend to know the type (class with subclasses) of
what is in each variable, they can find their way in the spaghetty.
Formally it's still very messy, but who cares, programming IS a matter
of psychology after all ;-)

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

Jace Benson wrote:
Ok I have read alot of things on zend.com, php.net and other sites went
to the wikibooks to try to understand how to use a class. I have this
project I want to do that I am sure would work great with a class. I
just don't grasp the whole concept, and how to do it.

I want to make a Collectable Card Game Draft Engine...(if any of you
play VS System, LOTR, Magic: The Gathering, you know what I am talking
about.)

It would be way to complicated for just typing in regular functions and
calling em.

So this is what I've seen That I don't understand.

Say i have a database with cards that are common(c), uncommon(u),
rare(r) from 3 sets alpha(a), beta(b), unlimited(u).

I need to 1st create 24 packs that contain 11commons, 3uncommons, and
1rare each.

Bam thats a class.

would it look like this?
Class CreateDraft{
var $set;
var $rarity;
function SelectRandomCard{
//connect to database in file header
//
$querycardbase = "SELECT * FROM `mtg_base` WHERE rarity = $rarity
AND set = $set LIMIT $rarity_num";//rarity and rarity_num are related
c=11,u=3,r=1, set dictates cards available.
$querycardbase_result6 = @mysql_query ($querycardbase);
while ($cardbaserow = @mysql_fetch_array ($querycardbase_result)) {

$packarr = $cardbaserow[card_id]
}
function InsertPack{
$insertpack = "SQL STATEMENT INSERTING AN ARRAY";//I know, i know
its late and I just want to understand.
}
}

I guess I am asking for help.. Because I do not understand.

Oct 7 '05 #6
(I posted this also a few months ago in the XP yahoo group) When I
explain object-oriented programming, I usually draw the parallel
to electronic devices.

When I was young, I had a tape recorder dating from about 1965. It came
with a _huge_ electrical scheme that contained everything. You could
look at it for hours and still discover new parts of that same tape
recorder. For programmers, it looked a lot like an old BASIC program.

We don't build tape recorders like that anymore. Factories make not one
tape recorder, but a whole line of them. With different size, colour,
power, with an equalizer, with extra engine speed, etc.
If you open a modern tape recorder, you see that it is built up of
sub-assemblies that are plugged together. You can easily change the tone
control for an equalizer, or repair the left preamplifier by simply
replacing it for a new one.
These are, for me, objects. They are separately testable (with unit
tests), allow reuse (the line of tape recorders, but the preamplifier is
also used in an MP3-player) and have a small task.
A plug is the object's interface. Circumvening the plug (exposing
internal details or using global variables or singletons) is the same as
hard-wiring a point on one circuit board to another. You can even SEE it
is bad in electronics, because hard-wired objects are not separate
anymore, cannot be separately tested, etc.

Best regards
Oct 8 '05 #7
Well... I am trying to understand here. Before I start, thanks for all
the information you've given me.

So please correct me if I am wrong.

Classes are a container.. if you will something to put what a <thing>
does.
if for instance I was making a program on a pet. I would want to label
it Class Pet {...}
(dont be so tight on the gramatical errors, I am just trying to figure
this out).. Anyways In the class Pet I would put in it the
methods?(these are also the functions)? that the pet would do. So say
I wanted to call the class pet and make a new instance of a dog and i
wanted that dog to poop.
Would this be how i should look at that in OO programming?
//make this class
//classes dont create things methods do
Class Pet {
var $pets_name;
function ChooseAPet() {
//some function pulling data from an array printing
//it to a form to select it and send it back with a name
}
}
Class Action {
var $action;
function Action(){
//this will be called whenever the class is caled
//some thing like before but pulling data for what an animal can
do.
}
function Stop(){
//something to stop an action for instance
//a pet might take a long time to sleep but not long to jump
}
function Create(){
//when some actions happen things are created like stools
}
}

not the best example but this would be a valid theroized Class
design..?

I feel like i dont' get it. I under stand to seperate is good, but I
am lost.

Oct 11 '05 #8
In general, OOP is more or less what your example shows. The class
defines what the object is and can do, while the object actually *is*
something (an instance of the class) and *does* something. See if this
pseudocode helps...
Class Dog
{
var race;
var food_it_likes;

function Bark
{
....
}

function Poop
{
....
}

} //End Dog Class
//You have just defined what a dog is and can do, so that you can have
multiple dogs doing stuff. Then, in your program...

Dog Vincent;
Dog Toby;

Toby.race = "Scottish Terrier";
Toby.food_it_likes = "Tasty Chicken";
Vincent.race = "Chiuaua";
Vincent.food_it_likes = "Human Flesh";

Vincent.Bark;
Toby.Poop;

//You now *actually* have two dogs who can bark and poop. One is
barking (Vincent the scary assasin little chiuaua), and the other is
pooping (Toby the elegant black Scottish).

Greetings

Oct 11 '05 #9
Jace Benson wrote:
Well... I am trying to understand here. Before I start, thanks for all
the information you've given me.

So please correct me if I am wrong.

Classes are a container.. if you will something to put what a <thing>
does.
if for instance I was making a program on a pet. I would want to label
it Class Pet {...}
(dont be so tight on the gramatical errors, I am just trying to figure
this out).. Anyways In the class Pet I would put in it the
methods?(these are also the functions)? that the pet would do. So say
I wanted to call the class pet and make a new instance of a dog and i
wanted that dog to poop.
Would this be how i should look at that in OO programming?
//make this class
//classes dont create things methods do
Class Pet {
var $pets_name;
function ChooseAPet() {
//some function pulling data from an array printing
//it to a form to select it and send it back with a name
}
}
Class Action {
var $action;
function Action(){
//this will be called whenever the class is caled
//some thing like before but pulling data for what an animal can
do.
}
function Stop(){
//something to stop an action for instance
//a pet might take a long time to sleep but not long to jump
}
function Create(){
//when some actions happen things are created like stools
}
}

not the best example but this would be a valid theroized Class
design..?

I feel like i dont' get it. I under stand to seperate is good, but I
am lost.


Hi, Jace,

Samuel has given you an excellent example. I'll try another (in a sec.).

The whole idea of object oriented programming is to bring "real world"
objects into the "programming world". That is, to create something in
the programming world which mimics what we're already familiar with.

If you had a real world pet, would you think of it as performing
"Action", "Stop" and "Create"? Or would you think of it as performing
"Bark", "Eat", "Sit", "Poop"?

The other example I've used in a lot of classes - an automobile. Take
some basic actions - start, stop, change gear, accelerate and stop.

The car itself keeps track of basic things like its running status, the
gear it's in, its speed, and how much gas is in the tank.

When you "start" the car, some things must be in place. The car must
not already be started, there must be gas in the tank and the gear must
be in park or neutral (assuming an automatic transmission).

To accelerate, the engine must be running, the brake off and the
transmission in gear.

The beauty here is - you, as a user of the car class, don't have to
worry about testing the various states - the car class will do it for
you (for instance - lets say you add a new status "Battery Charged").
You change the "Start" method to test for this - but don't need to
change anything else in your program.

OO programming is a completely different way of thinking. Interestingly
enough, in my classes I've found the people with the least programming
experience typically have the least trouble making the switch. Those
with lots of programming experience have the most trouble. It's quite
difficult to "unlearn" years of learning!
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 11 '05 #10
Samuel wrote:
In general, OOP is more or less what your example shows. The class
defines what the object is and can do, while the object actually *is*
something (an instance of the class) and *does* something. See if this
pseudocode helps...
Class Dog
{
var race;
var food_it_likes;

function Bark
{
...
}

function Poop
{
...
}

} //End Dog Class
//You have just defined what a dog is and can do, so that you can have
multiple dogs doing stuff. Then, in your program...

Dog Vincent;
Dog Toby;

Toby.race = "Scottish Terrier";
Toby.food_it_likes = "Tasty Chicken";
Vincent.race = "Chiuaua";
Vincent.food_it_likes = "Human Flesh";

Vincent.Bark;
Toby.Poop;

//You now *actually* have two dogs who can bark and poop. One is
barking (Vincent the scary assasin little chiuaua), and the other is
pooping (Toby the elegant black Scottish).

Greetings

This is obviously not PHP syntax (Samuel even says it's pseudocode), but
it could easily mislead people into a mistake that I kept making when I
started:

The PHP for some of those lines might be

$Vincent->race = "Chihuahua";

but

$Vincent->Bark();

If you leave out the parens, it's an (undeclared) property (variable)
not a method (function).

Colin
Oct 13 '05 #11
I may be one of those people that have problems converting to the OOP way of
thinking. I understand the car example and understand the idea of objects
doing things. Where I seem to be having the problem is in trying to convert
an exsisting Structured Programming style program into OOP. My program
basically allows users to upload files and manage them. I have created
files as an object and this seems to be OK, my problem is dealing with the
display of the files. This requires SQL queries and HTML tables. How
should I be thinking of these items in terms of OOP?

Am I causing myself more problems by trying to convert from an existing
program? Is there a good way to get started on determining which objects to
create?

Thanks,

-Mark
OO programming is a completely different way of thinking. Interestingly
enough, in my classes I've found the people with the least programming
experience typically have the least trouble making the switch. Those with
lots of programming experience have the most trouble. It's quite
difficult to "unlearn" years of learning!

Nov 2 '05 #12
Mark ??;-) wrote:
I may be one of those people that have problems converting to the OOP way of
thinking. I understand the car example and understand the idea of objects
doing things. Where I seem to be having the problem is in trying to convert
an exsisting Structured Programming style program into OOP. My program
basically allows users to upload files and manage them. I have created
files as an object and this seems to be OK, my problem is dealing with the
display of the files. This requires SQL queries and HTML tables. How
should I be thinking of these items in terms of OOP?

Am I causing myself more problems by trying to convert from an existing
program? Is there a good way to get started on determining which objects to
create?

Thanks,

-Mark


One quick way to think about conversion is that objects are all the
nouns and methods are all the verbs. This is somewhat simplistic but
often is a good way to start.

When you say you have encapsulated the files as an object, does this
mean that you have a file object or that you have objects that access
files? In the first example, you would have generic methods (read,
write, delete, create) that concerned all files as a generic type. In
the second example, file access would simply be a product of satisfying
a method on an object.

Put another way - are you sure that 'file' is an appropriate object when
talking about 'display' methods? I think it is more likely that you want
to display a specific instance of a file or some object that simply uses
a 'file' to satisfy some of its methods.

For example: The 'car' object may use a file object, a database object
and an HTML object to assist in the implementation of certain methods,
but the real object (noun) used by the system is 'car'. We would want to
have methods like 'save', 'load' and 'toHTML' as file, database and
display methods of the object 'car'.

e.g.
// instantiate a new car object
$car = new Car();

// read in the data for an Acura 3.2 TL
$car->load('Acura 3.2 TL');

// make the car red
$car->setColor('red');

// display all the data including the color as HTML
$car->printHTML();

Now the 'load' method may actually use the File object to read in the data.

e.g.

function load($model) {
$file = new File();
try {
$this->carData = $file->read($model);
} catch( Exception $e ) {
...
}
}

As for conversion of structured code, it really comes down to how well
you can divorce the intent of the code from the implementation of the
code. What is the code really trying to achieve? What objects is it
really dealing with? How may these be implemented in an object model and
what methods does each object then need to support?

Try taking one path through the existing code and seeing which objects
and methods would make sense. Now add another path. Does your model
change and how?

-david-

Nov 2 '05 #13
> When you say you have encapsulated the files as an object, does this mean
that you have a file object or that you have objects that access files? In
the first example, you would have generic methods (read, write, delete,
create) that concerned all files as a generic type. In the second example,
file access would simply be a product of satisfying a method on an object.


I have file objects. Basically I have a form that gets input from a user
including things like date, time, section, and the selected file. I am
considering this my file object, which I will then upload, display, or
delete. Maybe I need to create different objects to deal with the display
portion, I don't know.

On a slight tangent..the file information form consists of several <select>
lists which allow users to select the day, month, year, etc. I've have
tried turning this group of selects into a class, but I am having problems
with the array of values. If I post the code would someone be able to guide
me through the process of converting this group of functions into a class?

Thanks,

-Mark
Nov 3 '05 #14
Mark ??;-) wrote:
When you say you have encapsulated the files as an object, does this mean
that you have a file object or that you have objects that access files? In
the first example, you would have generic methods (read, write, delete,
create) that concerned all files as a generic type. In the second example,
file access would simply be a product of satisfying a method on an object.
I have file objects. Basically I have a form that gets input from a user
including things like date, time, section, and the selected file. I am
considering this my file object, which I will then upload, display, or
delete. Maybe I need to create different objects to deal with the display
portion, I don't know.


I think you are confusing the file object concept with the file instance
concept. When the user fills in your object - either via the constructor
or via setter methods on it - it is dealing with an instance of the
object. The instance should be able to produce an HTML representation of
itself in just the same way it could product a regular text
representation of itself with, say, var_dump().

So, let's say your file uses setter methods. Your code for file would
look something like this when used as an instance:

$file = new File();
$file->setDate('2005-11-03');
$file->setTime('06:35:27');
$file->setPath('c:\foo');

Then when you wanted to express this instance of the object File as
HTML, you would use the toHTML() method (or build the HTML via getter
methods). For example:

<body>
<h1>Your File</h1>
<?php $file->toHTML() ?>
</body>

In your File object, you would have something like the following:

class File {
private $date = null;
private $time = null;
private $path = null;

function setDate($date) {
$this->date = $date;
}
// other setters

function toHTML() {
return "<table border=\"0\">"
"<tr>"
"<th>Date:</th><td>$this->date</td>"
"<th>Time:</th><td>$this->time</td>"
"<th>Location:</th><td>$this->path</td>"
"</tr>"
"</table>";
}
}

Note: I would probably add $date, $time and $path to the constructor
since that information seems to always be required for an instance of File.

On a slight tangent..the file information form consists of several <select>
lists which allow users to select the day, month, year, etc. I've have
tried turning this group of selects into a class, but I am having problems
with the array of values. If I post the code would someone be able to guide
me through the process of converting this group of functions into a class?


Email me a copy and I'll take a look. (davidDOThaynes2ATsympaticoDOTca)

-david-

Nov 3 '05 #15
> Email me a copy and I'll take a look. (davidDOThaynes2ATsympaticoDOTca)

-david-


Thanks for all your help. I am working on understanding the class. I did
make a little bit of a change and modeled this method on yours. I had to
add the str_pad, because I just can't stand the leading zeros dropping off.
I will work with your class some more tomorrow and try and make it work with
my form.

-Mark

function printMinute() {
echo "<select name=\"Minute\">\n";
foreach ( range(0,55,5) as $option) {
if ( $option == $this->minute) {
echo "<option selected>" . str_pad($option, 2, 0,
STR_PAD_LEFT) . "</option>\n";
}else {
echo "<option>" . str_pad($option, 2, 0, STR_PAD_LEFT) .
"</option>\n";
}
}
echo "</select>\n";
}
Nov 4 '05 #16
Mark ??;-) wrote:
Email me a copy and I'll take a look. (davidDOThaynes2ATsympaticoDOTca)

-david-


Thanks for all your help. I am working on understanding the class. I did
make a little bit of a change and modeled this method on yours. I had to
add the str_pad, because I just can't stand the leading zeros dropping off.
I will work with your class some more tomorrow and try and make it work with
my form.

-Mark

function printMinute() {
echo "<select name=\"Minute\">\n";
foreach ( range(0,55,5) as $option) {
if ( $option == $this->minute) {
echo "<option selected>" . str_pad($option, 2, 0,
STR_PAD_LEFT) . "</option>\n";
}else {
echo "<option>" . str_pad($option, 2, 0, STR_PAD_LEFT) .
"</option>\n";
}
}
echo "</select>\n";
}

You could use printf('%02d', $option) instead of str_pad if you wanted to.

-david-

Nov 4 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: vrillusions | last post by:
I've been using functions since I first started using php, but I've been hearing more and more about classes, which I never really looked at that much. I understand the whole OO programming...
6
by: beliavsky | last post by:
I have started using classes with Python and have a question about their use. In Python, 'attributes are all "public" and "virtual" in C++ terms; they're all accessible everywhere and all looked...
7
by: verbatime | last post by:
Please explain me how this works - or should work: Got my two classes - bcBasic (baseclass) and the derived cBasic. //--------------------------------------- class bcBasic { int number;...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
11
by: mem | last post by:
Concrete classes are ones that can be instantiated directly, as long as it doesn't have pure virtual function. However, people suggest that "Don't derive from concrete classes." Does this mean...
6
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by...
25
by: Brian | last post by:
Can some one please tell me what I'm doing wrong. I'm trying to create a class called Dog, but Visual Basic tells me that I can't enter Wolf.age....why is this? Public Class Form1 Public Class...
7
by: TClancey | last post by:
Hi all. I'm having some problems with a project I'm working on. I have a Class Library which contains several Component Classes, each working independantly. It seems that I can't have two...
4
by: Eric | last post by:
I was wondering what people thought about the information found at: http://g.oswego.edu/dl/mood/C++AsIDL.html Specifically, I am interested in the following recommendation: ---- Since...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.