Forum Moderators: coopster
I need your helps.My problem is / how to select title from query or define var and put to header.php.
i try if else steatments but fail.my code this
if(isset($_GET['id'])){
$title = $$obj->title($_GET['id']) ;
}else{
$title = 'CATS' ;
}
but first title var only print top-left of the screen
Req.page codes at below.help please
Ex(query/print) main_category title = 'MAIN CAT';
get_category title = $row['cat_name'];
HEADER.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
<title>How to </title>
<link rel="stylesheet" href="./demo/dialog.css" media="screen" />
<style type="text/css">
/* basic formatting */
body {background-color: #414141;}
h1 {font-size: 12px; color: #ffffff; font-weight:bold; font-family:arial; display:block; padding: 5px 10px 5px 10px;}
p {font-size: 9px; color: #ffffff; font-weight:bold; font-family:arial; padding: 5px 10px 5px 10px; display:block; line-height:1.6em;}
</style>
</head> category_class.php
<?phpclass category {
var $host;
var $username;
var $password;
var $db;
function connect() {
$con = mysql_connect($this->host, $this->username, $this->password)or die(mysql_error());
mysql_select_db($this->db, $con)or die(mysql_error());
}
function main_category(){
$sql = "SELECT * FROM category" ;
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)){
echo '<a href ="./category.php?id=' . $row['cat_id'] . '"><img src="./demo/images/' . $row['cat_image'] . '"></a>';
}
}
function get_category($id = ''){
if($id !=""):
$id = mysql_real_escape_string($id);
$sql = "SELECT id, article_name, article_sdesc, article_desc, cat_image, article_cat, cat_id FROM articles join category on articles.article_cat = category.cat_id where cat_id='$id' ";
else:
$sql = "SELECT * FROM articles limit 12";
endif;
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) !=0) :
while($row = mysql_fetch_assoc($res)){
echo '<div class="dialog1"><div class="content">
<div class="t"></div>
<div class="floatbox">
<img border="0" src="imaj.jpg" width="55" height="55" />
</div>';
echo '<h1><a href="article.php?id=' . $row[id] . '">' . $row['article_name'] . '</a></h1>' ;
echo '<p>' . $row['article_sdesc'] . '</p>' ;
echo '</div>
<div class="b"><div></div> </div></div></div>';
}
$cat_title = $row['cat_name'];
else:
echo '#*$!';
endif;
}
}
?>
category.php
<?php
include 'class/category_class.php';$obj = new category();
$obj->host = 'localhost';
$obj->username = 'demo';
$obj->password = 'demo';
$obj->db = 'phpfreaks';
$obj->connect();
?>
<?php
include 'includes/header.php';
?>
<table width="833" border="1" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<?php
if(isset($_GET['id'])):
$obj->get_category($_GET['id']);
else:
$obj->main_category();
endif;
?></td>
</tr></table>
<?php
include 'includes/footer.php';
?>
Do you find any of these past discussions [google.com] helpful?