[PHP] Re: better way to mix html and php code?

2005-11-17 Thread James Benson
None, their all messy and terribly hard to read, I would use CSS instead 
of tables, that way their would be not much need to change any HTML code 
incase you wanted to re-design your webpage with another style or make 
slight alterations etc, HTML coders should be able to understand CSS so 
would be able to identify the bits of HTML within your PHP code if it 
needed changing, your code would be a lot easier to read using CSS, 
easier to alter and take up roughly 25% less space.



James

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: better way to mix html and php code?

2005-11-17 Thread Dan Baker
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 Hi to all,
 always wondered what's better way to mix html and php code. Here are three 
 ways of the same code. Which one you prefer? (And why, of caurse :))
(snip)
 I think third solution would be the best solution?

IF you are doing a complex site, then the third option is almost mandatory. 
You typically do not know what code will be in the header, until you have 
processed some of the page.  Building the page as-you-go, allows for easy 
alteration of previously built HTML code.  Complex sites are extremely 
difficult to create using the template approach, because of the variety of 
output.

I would highly agree with James Benson about CSS.

DanB 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: better way to mix html and php code?

2005-11-17 Thread Robert Cummings
On Thu, 2005-11-17 at 14:34, Dan Baker wrote:
 [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
  Hi to all,
  always wondered what's better way to mix html and php code. Here are three 
  ways of the same code. Which one you prefer? (And why, of caurse :))
 (snip)
  I think third solution would be the best solution?
 
 IF you are doing a complex site, then the third option is almost mandatory. 
 You typically do not know what code will be in the header, until you have 
 processed some of the page.  Building the page as-you-go, allows for easy 
 alteration of previously built HTML code.  Complex sites are extremely 
 difficult to create using the template approach, because of the variety of 
 output.

Ummm... bullturds :)

Here is an example of a layout template:

-
jinn:prepend/
html

head
  titlejinn:pageTitle//title

  style type=text/css
  !--
jinn:template path=css/main.template/
  --
  /style

  jinn:accumulatorFlush name=javaScriptTags/
  jinn:accumulatorFlush name=javaScriptTags dynamic=true/

  script type=text/javascript language=javascript
  !-- //

  jinn:accumulatorFlush name=javaScript/
  jinn:accumulatorFlush name=javaScript dynamic=true/

  function onLoadRoutines()
  {
jinn:accumulatorFlush name=javaScriptOnLoad/
jinn:accumulatorFlush name=javaScriptOnLoad dynamic=true/
  }

  // --
  /script

/head

body onLoad=javascript:onLoadRoutines() bgcolor=#ff
marginheight=5 marginwidth=10 topmargin=0 l
-

Now anywhere in the modules (which incidentally get loaded before the
content), or anywhere else in a sub-template content can be accumulated
in any of the above accumulator names. I have worked on plenty of
complex sites, and my JavaScript and other content always goes EXACTLY
where it's supposed to be, regardless of where the logic exists that
determines it's need to exist. For instance to include on load
javascript from any module:
-

$sAcc = $this-getServiceRef( 'accManager' );
$acc = $sAcc-getAccumulatorRef( 'javaScriptOnLoad' );

$acc-append( alert( 'F!' );\n );

 I would highly agree with James Benson about CSS.

I agree CSS is great, but it's not everything. Custom tags allow one to
embed macro and meta semantics into a page without the cumbersome nature
of PHP function calls. For instance I find this meta tag handy in many
sites I create:

project:searchable
Some content that the site's search feature can search upon.
/project:searchable

Another one that my designer friends REALLY like:

project:restrict access=admin, manager
Some content that only admin and management can view.
/project:restrict

So templates aren't just about making pretty tables, though they can do
that quite well too.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: better way to mix html and php code?

2005-11-16 Thread Al

[EMAIL PROTECTED] wrote:

Hi to all,
always wondered what's better way to mix html and php code. Here are 
three ways of the same code. Which one you prefer? (And why, of caurse 
:))


Solution 1: 
 


?php
require 'includes/header.php';

$cat_parent = $_GET['cat_parent'];
$cat_id = $_GET['cat_id'];

echo 'table border=0 align=center cellpadding=1 cellspacing=0 
style=border: 1px solid #EBEBEB; padding: 25px;';

echo 'tr';
echo 'td align=left height=35 valign=top 
colspan=2bu'. $_SESSION['CATEGORIES']['name'][$cat_parent] .'  
'. $_SESSION['CATEGORIES']['name'][$cat_id] .'/u/b/td';
echo  'td align=center valign=bottom colspan=2a 
href=new_product.php?cat_id='.$cat_id.'cat_parent='.$cat_parent.' 
style=font-size: 11px; color: gray;[ Add New Product ]/a/td';

echo '/tr';

$query = my_query(
   SELECT chp.products_prod_id, p.prod_id, p.prod_name, 
p.prod_no, p.prod_status

   FROM categories_has_products as chp, products as p
   WHERE chp.categories_cat_id = '.$cat_id.' AND 
chp.products_prod_id = p.prod_id

   , 0);
while($result = mysql_fetch_array($query))
{
   echo 'tr';
   echo 'td align=left valign=topraquo; '. 
$result['prod_name'] .'/td';
   echo 'td align=center valign=top[ '. $result['prod_no'] 
.' ]/td';

   echo 'td align=center valign=top';
   echo 'img src=../images/icon_edit2.gif alt=EDIT 
width=14 height=14 hspace=0 vspace=0 border=0';
   echo 'a 
href=products.php?cat_id='.$cat_id.'cat_parent='.$cat_parent.'action=deleteprod_id='.$result['prod_id'].' 
onclick=return confirm(\'Do you really want to delete this 
product?\');img src=../images/icon_delete.gif alt=DELETE 
width=14 height=14 hspace=5 vspace=0 border=0/a';

   switch($result['prod_status'])
   {
   case 'live':
   echo 'a 
href=products.php?new_status=hiddenprod_id='.$result['prod_id'].'cat_id='.$cat_id.'cat_parent='.$cat_parent.'img 
src=../images/status_live.gif alt=LIVE width=13 height=13 
hspace=2 vspace=0 border=0/a';

   break;

   case 'hidden':
   echo 'a 
href=products.php?new_status=liveprod_id='.$result['prod_id'].'cat_id='.$cat_id.'cat_parent='.$cat_parent.'img 
src=../images/status_hidden.gif alt=HIDDEN width=13 height=13 
hspace=2 vspace=0 border=0/a';

   break;

   case 'temp':
   echo 'b[T]/b';
   break;

   }
   echo '/td';
   echo '/tr';
}
echo '/table';

include 'includes/footer.php';
?


Solution 2: 
 


?php
require 'includes/header.php';

$cat_parent = $_GET['cat_parent'];
$cat_id = $_GET['cat_id'];
?
table border=0 align=center cellpadding=1 cellspacing=0 
style=border: 1px solid #EBEBEB; padding: 25px;

   tr
   td align=left height=35 valign=top colspan=2bu?= 
$_SESSION['CATEGORIES']['name'][$cat_parent] ?  ?= 
$_SESSION['CATEGORIES']['name'][$cat_id] ?/u/b/td
   td align=center valign=bottom colspan=2a 
href=new_product.php?cat_id=?= $cat_id ?cat_parent=?= $cat_parent 
? style=font-size: 11px; color: gray;[ Add New Product ]/a/td

   /tr
?php
$query = my_query(
   SELECT chp.products_prod_id, p.prod_id, p.prod_name, 
p.prod_no, p.prod_status

   FROM categories_has_products as chp, products as p
   WHERE chp.categories_cat_id = '.$cat_id.' AND 
chp.products_prod_id = p.prod_id

   , 0);
while($result = mysql_fetch_array($query))
{
?
   tr
   td align=left valign=topraquo; ?= $result['prod_name'] 
?/td

   td align=center valign=top[ ?= $result['prod_no'] ? ]/td
   td align=center valign=top
   img src=../images/icon_edit2.gif alt=EDIT width=14 
height=14 hspace=0 vspace=0 border=0
   a href=products.php?cat_id=?= $cat_id ?cat_parent=?= 
$cat_parent ?action=deleteprod_id=?= $result['prod_id'] ? 
onclick=return confirm('Do you really want to delete this 
product?');img src=../images/icon_delete.gif alt=DELETE 
width=14 height=14 hspace=5 vspace=0 border=0/a


?php
   switch($result['prod_status'])
   {
   case 'live':
   echo 'a 
href=products.php?new_status=hiddenprod_id='.$result['prod_id'].'cat_id='.$cat_id.'cat_parent='.$cat_parent.'img 
src=../images/status_live.gif alt=LIVE width=13 height=13 
hspace=2 vspace=0 border=0/a';

   break;

   case 'hidden':
   echo 'a 

Re: [PHP] Re: better way to mix html and php code?

2005-11-16 Thread Anas Mughal
I wouldn't pick any of those approaches.

We did a quick POC for a site using approach #1.
Unfortunately, that POC code has lived to go into production.

Now, we are looking into some sort of framework that would allow us to
separatate of PHP code and HTML -- as much as possible. (Looking into Smarty
right now.) Haven't finalized the approach/framework yet. Any suggestions
would be welcomed.

Thanks.



On 11/16/05, Al [EMAIL PROTECTED] wrote:

 [EMAIL PROTECTED] wrote:
  Hi to all,
  always wondered what's better way to mix html and php code. Here are
  three ways of the same code. Which one you prefer? (And why, of caurse
  :))
 
  Solution 1:
 
 
 
  ?php
  require 'includes/header.php';
 
  $cat_parent = $_GET['cat_parent'];
  $cat_id = $_GET['cat_id'];
 
  echo 'table border=0 align=center cellpadding=1 cellspacing=0
  style=border: 1px solid #EBEBEB; padding: 25px;';
  echo ' tr';
  echo ' td align=left height=35 valign=top
  colspan=2bu'. $_SESSION['CATEGORIES']['name'][$cat_parent] .' 
  '. $_SESSION['CATEGORIES']['name'][$cat_id] .'/u/b/td';
  echo ' td align=center valign=bottom colspan=2a
  href=new_product.php?cat_id='.$cat_id.'cat_parent='.$cat_parent.'
  style=font-size: 11px; color: gray;[ Add New Product ]/a/td';
  echo ' /tr';
 
  $query = my_query(
  SELECT chp.products_prod_id, p.prod_id, p.prod_name,
  p.prod_no, p.prod_status
  FROM categories_has_products as chp, products as p
  WHERE chp.categories_cat_id = '.$cat_id.' AND
  chp.products_prod_id = p.prod_id
  , 0);
  while($result = mysql_fetch_array($query))
  {
  echo ' tr';
  echo ' td align=left valign=topraquo; '.
  $result['prod_name'] .'/td';
  echo ' td align=center valign=top[ '. $result['prod_no']
  .' ]/td';
  echo ' td align=center valign=top';
  echo ' img src=../images/icon_edit2.gif alt=EDIT
  width=14 height=14 hspace=0 vspace=0 border=0';
  echo ' a
  href=products.php
 ?cat_id='.$cat_id.'cat_parent='.$cat_parent.'action=deleteprod_id='.$result['prod_id'].'
  onclick=return confirm(\'Do you really want to delete this
  product?\');img src=../images/icon_delete.gif alt=DELETE
  width=14 height=14 hspace=5 vspace=0 border=0/a';
  switch($result['prod_status'])
  {
  case 'live':
  echo 'a
  href=products.php
 ?new_status=hiddenprod_id='.$result['prod_id'].'cat_id='.$cat_id.'cat_parent='.$cat_parent.'img
  src=../images/status_live.gif alt=LIVE width=13 height=13
  hspace=2 vspace=0 border=0/a';
  break;
 
  case 'hidden':
  echo 'a
  href=products.php
 ?new_status=liveprod_id='.$result['prod_id'].'cat_id='.$cat_id.'cat_parent='.$cat_parent.'img
  src=../images/status_hidden.gif alt=HIDDEN width=13 height=13
  hspace=2 vspace=0 border=0/a';
  break;
 
  case 'temp':
  echo 'b[T]/b';
  break;
 
  }
  echo ' /td';
  echo ' /tr';
  }
  echo '/table';
 
  include 'includes/footer.php';
  ?
 
 
  Solution 2:
 
 
 
  ?php
  require 'includes/header.php';
 
  $cat_parent = $_GET['cat_parent'];
  $cat_id = $_GET['cat_id'];
  ?
  table border=0 align=center cellpadding=1 cellspacing=0
  style=border: 1px solid #EBEBEB; padding: 25px;
  tr
  td align=left height=35 valign=top colspan=2bu?=
  $_SESSION['CATEGORIES']['name'][$cat_parent] ?  ?=
  $_SESSION['CATEGORIES']['name'][$cat_id] ?/u/b/td
  td align=center valign=bottom colspan=2a
  href=new_product.php?cat_id=?= $cat_id ?cat_parent=?= $cat_parent
  ? style=font-size: 11px; color: gray;[ Add New Product ]/a/td
  /tr
  ?php
  $query = my_query(
  SELECT chp.products_prod_id, p.prod_id, p.prod_name,
  p.prod_no, p.prod_status
  FROM categories_has_products as chp, products as p
  WHERE chp.categories_cat_id = '.$cat_id.' AND
  chp.products_prod_id = p.prod_id
  , 0);
  while($result = mysql_fetch_array($query))
  {
  ?
  tr
  td align=left valign=topraquo; ?= $result['prod_name']
  ?/td
  td align=center valign=top[ ?= $result['prod_no'] ? ]/td
  td align=center valign=top
  img src=../images/icon_edit2.gif alt=EDIT width=14
  height=14 hspace=0 vspace=0 border=0
  a href=products.php?cat_id=?= $cat_id ?cat_parent=?=
  $cat_parent ?action=deleteprod_id=?= $result['prod_id'] ?
  onclick=return confirm('Do you really want to delete this
  product?');img src=../images/icon_delete.gif alt=DELETE
  width=14 height=14 hspace=5 vspace=0 border=0/a
 
  ?php
  switch($result['prod_status'])
  {
  case 'live':
  echo 'a
  href=products.php
 ?new_status=hiddenprod_id='.$result['prod_id'].'cat_id='.$cat_id.'cat_parent='.$cat_parent.'img
  src=../images/status_live.gif alt=LIVE width=13 height=13
  hspace=2 vspace=0 border=0/a';
  break;
 
  case 'hidden':
  echo 'a
  href=products.php
 ?new_status=liveprod_id='.$result['prod_id'].'cat_id='.$cat_id.'cat_parent='.$cat_parent.'img
  src=../images/status_hidden.gif alt=HIDDEN width=13 height=13
  hspace=2 vspace=0 border=0/a';
  break;
 
  case 'temp':
  echo 

[PHP] Re: better way to mix html and php code?

2005-11-16 Thread Roman Ivanov

For long strings I suggest using
echo EOTHML
EOHTML;

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php