Hi, I guess it's time for my first post here :)

I've managed to create a php script that can run through a MySQL table and print out OPTIONS for a HTML SELECT tag. That was Google 101. But I want to keep my php and HTML separate so i've used HTML_Template_IT package from PEAR, and that worked out just fine until I had to do that select list. Does anyone know a way to do this the OOP way?

It would be great if someone could point me in the right direction.

Thank You :)

Recommended Answers

All 2 Replies

Hello DJWK , I really enjoyed your enthusiasm about discovering OOP .I don’t really believe that it is something new in logic. A lot of code that in one of my old jobs I had to support had been made with COBOL witch is not an OOP language , but some people out there managed to enter OO programming even through ’70 and even COBOL. So I believe that OOP is the presupposition for today programming, I am not sure about tomorrow. In your question.. I have no clue what is HTML_Template_IT , just state what you want to do and of course there is an OOP way to do it.

I got it! :)

It wasn't that difficult, just needed a good night sleep and it came to me.

All that was needed was to put the BEGIN and the END of the block in the right place.
HTML:

<tr><td>Category:<td><select name="category">
<!-- BEGIN CATEG -->
<option>{CATEG}
<!-- END CATEG -->

Now the php script can place options from the database as long as there are rows in the table.
PHP:

// query for newscategories
$result = mysql_query ("SELECT category FROM newscategories", $connection);

while ($row = mysql_fetch_array($result))
{
  // working with CATEG block
  $template->setCurrentBlock("CATEG");

  // assign row data to template holders
  $template->setVariable("CATEG", $row["category"]);

  //parse CATEG block
  $template->parseCurrentBlock();
}

So it wasn't that complicated after all.

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.