Hi all, I've finally gotten a handle on object-oriented programming (it took ages), and I really like it. But I'm still struggling with conceptualizing some things. For example, if I want to make a form using objects, do I make a Form class with a method like startFORM($name_of_action_page, $method), then another method like inputBox($name_of_box), etc. until I get to closeFORM(). Lets say I do it this way, then if I want to put the form in a table to straight things out, do I place the methods in between the html tags <td></td>. If I do that, where do I put the TRY and CATCH statements. Or do I have to use them? I want to make a drop down box and be able to populate it with whatever I place in the parameters. Is that how I would do it? All of the books I've been looking at are about big classes, XMLWriter, but what I need is more about how to use objects and classes on basic things on a website. Thanks for the help.

Recommended Answers

All 6 Replies

Is this a php or javascript question because aren't the try and catch statements part of the javascript language. If that is the case then perhaps you are posting in the wrong section. Also could you please send some code to explain your question.
From what I can understand in your context if you are wanting to display or execute data inside the <td></td> tags then yes you would place the javascript between the <td></td> tags. Otherwise please explain further with code samples.

This is definitely a PHP question. Here's a code sample of what I'm talking about:

try {
    $product = new Categories(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
    $product->setCategoryName($categoryName);
    $product->setTableName("$tableValue");
    $product->readKeyArray($keyArray, $valueArray);    
    $product->enterCategoryInDB();
    $product->getCategoryID();
    }
catch (Exception $e) {
    echo $e->getMessage();
}

Is this kind of coding only meant for the testing of a script? I'm trying to imagine how I would do something like this for a form that I put inside of a table. Here is another example I'm having problems with. It's a drop down box. Initially, I put code for the drop down box inside a table completely in the Product class's method, like this:

public function populatingDropDown()
	{
		$result = "<form action=\"enter_category.php\" method=\"post\" >";
		$result .= "<input type=\"hidden\" name=\"subcategoryID\" value=\"\" /><table><tr><td>";
		$result .= "<select name=\"categoryID\">";
		foreach ($this->_resultSet as $row) {
			foreach ($row as $field => $value) {
				if(strpos($field, 'ID')) {
					$result .= "<option value=\"" . $value . "\">";
				}
				if(strpos($field, 'Name')) {
					$result .= $value . "</option>";
				}
			}
		}
		$result .= "</select></form></td><td><input type=\"text\" name=\"subcategoryName\" /></td></tr>";
		$result .= "<tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Submit\" /></td></tr>";
		$result .= "</table>";
		echo $result;
 	}

But now I can see how this is too bulky and not reusable. So instead I'm thinking of making a Form class and putting in different methods that would make the form, such as I mentioned in the first posting. You see, this is more about conceptualizing how to attack a practical problem than actual code. Before I start writing the code I want to have an idea of where I'm going, and I'm finding it difficult to imagine because I have little experience in this area. I hope that explains it better.

This is definitely a PHP question. Here's a code sample of what I'm talking about:

try {
    $product = new Categories(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
    $product->setCategoryName($categoryName);
    $product->setTableName("$tableValue");
    $product->readKeyArray($keyArray, $valueArray);    
    $product->enterCategoryInDB();
    $product->getCategoryID();
    }
catch (Exception $e) {
    echo $e->getMessage();
}

Is this kind of coding only meant for the testing of a script? I'm trying to imagine how I would do something like this for a form that I put inside of a table. Here is another example I'm having problems with. It's a drop down box. Initially, I put code for the drop down box inside a table completely in the Product class's method, like this:

public function populatingDropDown()
	{
		$result = "<form action=\"enter_category.php\" method=\"post\" >";
		$result .= "<input type=\"hidden\" name=\"subcategoryID\" value=\"\" /><table><tr><td>";
		$result .= "<select name=\"categoryID\">";
		foreach ($this->_resultSet as $row) {
			foreach ($row as $field => $value) {
				if(strpos($field, 'ID')) {
					$result .= "<option value=\"" . $value . "\">";
				}
				if(strpos($field, 'Name')) {
					$result .= $value . "</option>";
				}
			}
		}
		$result .= "</select></form></td><td><input type=\"text\" name=\"subcategoryName\" /></td></tr>";
		$result .= "<tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Submit\" /></td></tr>";
		$result .= "</table>";
		echo $result;
 	}

But now I can see how this is too bulky and not reusable. So instead I'm thinking of making a Form class and putting in different methods that would make the form, such as I mentioned in the first posting. You see, this is more about conceptualizing how to attack a practical problem than actual code. Before I start writing the code I want to have an idea of where I'm going, and I'm finding it difficult to imagine because I have little experience in this area. I hope that explains it better.

Want to make generic form? I find that difficult.
I wanted to do something way back and I lacked time and haven't poked in for a while now. See the thread

Try just the following and report back here any errors.

$product = new Categories(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
    $product->setCategoryName($categoryName);
    $product->setTableName("$tableValue");
    $product->readKeyArray($keyArray, $valueArray);    
    $product->enterCategoryInDB();
    $product->getCategoryID();

I do not believe that the "try" and "catch" statements are valid php.

I do not believe that the "try" and "catch" statements are valid php.

They are as of PHP5

It seem so in PHP 5. I'm not sure in previous versions of PHP as I I'm not sure if I have used them at all

EDIT:
You have beaten me pritaeas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.