| 
	
 | 
 Posted by Curt Zirzow on 11/16/05 22:06 
On Wed, Nov 16, 2005 at 10:12:53AM -0600, afan@afan.net 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 2a: 
> ############################################################################################ 
<?php 
require 'includes/header.php'; 
  
$cat_parent = (int)$_GET['cat_parent']; 
$cat_id = (int)$_GET['cat_id']; 
 
$cat_names = $_SESSION['CATEGORIES']['name']; 
 
?> 
 
<table class="table-heading"> 
	<tr> 
		<td> 
			<?php echo htmlentities($cat_names[$cat_parent])?> :: 
			<?php echo htmlentities($cat_names[$cat_id])?> 
		</td> 
		<td> 
			<a href="new_product.php?cat_id=<?php echo $cat_id ?>&cat_parent=<?php echo $cat_parent?>">[ Add New Product ]</a> 
		</td> 
	</tr> 
</table> 
 
<table class="table-results"> 
<?php 
 
$sql = "SELECT  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"; 
 
$stmt = $dbh->prepare($sql); 
$stmt->bindParam(':cat_id', $cat_id); 
$stmt->execute(); 
 
$query_cat_id_parent = "products.php?cat_id=$cat_id&cat_parent=$cat_parent";  
while($result = $stmt->fetch()) 
{ 
	$query_product = "$query_cat_id_parent&prod_id={$result['prod_id']}"; 
 
	$del_link = "$query_product&action=delete"; 
 
	switch($result['prod_status']) 
	{ 
		case 'live': 
			$status_link = $query_product ."&new_status=hidden"; 
			$status_img  = 'live'; 
			break; 
 
		case 'hidden': 
			$status_link = $query_product ."&new_status=live"; 
			$status_img  = 'hidden'; 
			break; 
 
		default: 
		case 'temp': 
			$status_link = ''; 
			$status_img  = 'temp'; 
	} 
 
?> 
 
	<tr> 
		<td class="prod_name">» <?php echo htmlentities($result['prod_name']); ?></td> 
		<td class="prod_no">[ <?php echo $result['prod_no'] ?> ]</td> 
		<td class="prod_action"> 
			<img src="../images/icon_edit2.gif" alt="EDIT" width="14" height="14"> 
 
			<a onclick="return confirm('Do you really want to delete this product?');" 
				href="<?php echo $del_link?>"> 
				<img src="../images/icon_delete.gif" alt="DELETE" width="14" height="14"> 
			</a> 
 
			<?php if($status_link) { ?> 
				<a href="<?php echo $status_link?>"> 
					<img src="../images/status_<?php echo $status_img?>.gif"  
						alt="<?php echo $status_img?>" width="13" height="13"> 
				</a> 
			<?php } else { ?> 
				<img src="../images/status_<?php echo $status_img?>.gif"  
					alt="<?php echo $status_img?>" width="13" height="13"> 
			<?php } ?> 
 
		</td> 
	</tr> 
 
<?php 
 
} // $stmt->fetch() 
 
?> 
</table> 
 
<?php 
 
include 'includes/footer.php'; 
?> 
 
Curt. 
--
 
  
Navigation:
[Reply to this message] 
 |