Way to display pages?
Posted: Thu Mar 27, 2008 9:40 pm
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
need some help with my application, ive gotten to a certain point where I realized my current way of doing things is.... way too time consuming..
I'll show you what I got, please offer any suggestions or changes, or a better system of doing this.
I hate HTML, and use WYSIWYG editors to design the site, and what i need to do is be able to copy the HTML code and paste the relavant php code to display the correct stuff... any help would be appreciated!
Yep very basic stuff on just how to display something simple, like a news page! lol...
Question 1: can you read in an html file into a variable that has %s wherever i would want to insert php code and then ahve all the php code inserted afterwords then run it?
Question 2: is can you "include_once" a php file that displays the main content but store the html code in a variable so it can be displayed with the rest of the code, take a look:
or is this the best way of doing it!
index.php
page.php
news.php -basic example of the format im using currently
transactions.php
yeah this is where it gets really tricky....
transactions.php cont....
sorry for all the code, i don't expect you to go over all of it, but its there if you want it.
might be easier telling me how you do it instead of trying to 'fix' my system (which would work, just gets time consuming to post html into strings manually)
Thank you for your time!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
need some help with my application, ive gotten to a certain point where I realized my current way of doing things is.... way too time consuming..
I'll show you what I got, please offer any suggestions or changes, or a better system of doing this.
I hate HTML, and use WYSIWYG editors to design the site, and what i need to do is be able to copy the HTML code and paste the relavant php code to display the correct stuff... any help would be appreciated!
Yep very basic stuff on just how to display something simple, like a news page! lol...
Question 1: can you read in an html file into a variable that has %s wherever i would want to insert php code and then ahve all the php code inserted afterwords then run it?
Question 2: is can you "include_once" a php file that displays the main content but store the html code in a variable so it can be displayed with the rest of the code, take a look:
or is this the best way of doing it!
index.php
Code: Select all
<?php
define("ANTIHACKER", null);
include_once('database.php');//simple, mysql class to run queries and stuff...
include_once('page.php');
include_once('class_lib.php');//holds session class does session related stuff
$mysql = new MySQL();//"localhost", "smilies", "secret1", "cowofdoom");
$session = new Session($mysql);
$_SESSION['user'] = '1';
$moduleArray=array(
'home' => 'news.php',
'news' => 'news.php',
'viewtransactions' => 'transactions.php'
);
$titleArray=array(
'index.php' => 'Home',
'news.php' => 'News',
'transactions.php' => 'Transactions'
);
if(!isset($_REQUEST['module_MAIN']) || !isset($moduleArray[$_REQUEST['module_MAIN']])){
$module = $moduleArray['home'];
echo "IF";
}else{
$module = $moduleArray[$_REQUEST['module_MAIN']];
echo "ELSE<br>".$_REQUEST['module_MAIN']."<br>";
}
$title = $titleArray[$module];
$module = "Modules/".$module;
$page = new Page($title, date('Y'), "Smilies of Doom!", $mysql);
$page->addContent($module);
$page->display();
$mysql->close();
?>
Code: Select all
<?php
class Page {
private $page;
private $title;
private $copyright;
private $year;
private $footerAdded;
private $counter;
private $main;
private $mysql;
function Page($title, $year, $copyright, $mysql){
$this->page = '';
$this->main = '';
$this->title = $title;
$this->year = $year;
$this->copyright = $copyright;
$this->footerAdded = false;
$this->mysql = $mysql;
$this->addHeader();
}
function get(){
if(!$this->footerAdded)
$this->addFooter();
return $this->page;
}
function addContent($content){
//$this->page .= $content;
$this->main = $content;
include_once $this->main;
$pageData = new PageData($this->mysql);
$this->page .= $pageData->get();
}
private function addHeader(){
$this->page = <<<EOT
<html>
<head>
<title> $this->title </title>
</head>
<body>
EOT;
}
private function addFooter(){
$this->page .= <<<EOT
<div align='center'>© $this->year $this->copyright</div>
</body>
</html>
EOT;
}
function display(){
if(!$this->footerAdded)
$this->addFooter();
echo $this->page;
}
}
?>
Code: Select all
<?php
class PageData{
private $mysql;
function PageData($mysql){
$this->mysql = $mysql;
}
function get(){
$data = <<<EOF
<div id="body">
<a href="index.php?module_MAIN=viewtransactions">View Transactions</a><br />
<a href="file:///home/thadeus/">notes</a>
</div>
EOF;
return $data;
}
}
?>
Code: Select all
<?php
class PageData{
private $mysql;
function PageData($mysql){
$this->mysql = $mysql;
}
function get(){
if($_REQUEST['module_MAIN'] == 'viewtransactions'){
$data = "<div id='body'>" .
"<a href='index.php?'>Home</a><br />";
$sql = "".
"SELECT userID, date, transactions.name, amt, transactionTypes.transType, transactionCategories.transCat".
" FROM transactions, transactionTypes, transactionCategories".
" WHERE transactions.typeID = transactionTypes.typeID".
" AND transactions.catID = transactionCategories.catID".
" AND userID = ".$_SESSION['user']."".
" LIMIT 0 , 30";
$transactions = $this->mysql-queryGetResults($sql);
$transaction = $transactions->fetch();
do{
if($transaction['transType'] == 'Income')
$type = true;
else
$type = false;
transactions.php cont....
Code: Select all
$data .= "".
"<table style='text-align: left; width: 100%;' border='1'".
" cellpadding='2' cellspacing='2'>".
" <tbody>".
" <tr>".
" <td colspan='3' rowspan='1''>Deposits</td>".
" <td colspan='3' rowspan='1'>Withdrawals</td>".
" </tr>".
" <tr>".
" <td>Date</td>".
" <td>Name</td>".
" <td>Amount</td>".
" <td>Date</td>".
" <td>Name</td>".
" <td>Amount</td>".
" </tr>".
" <tr>".
" <td>";if($type){echo $transaction['date'];}."</td>".
" <td>".if($type){echo $transaction['name'];}."</td>".
" <td>".if($type){echo $transaction['amt'];}."</td>".
" <td>".if(!$type){echo $transaction['date'];}."</td>".
" <td>".if(!$type){echo $transaction['name'];}."</td>".
" <td>".if(!$type){echo $transaction['amt'];}."</td>".
" </tr>".
" </tbody>".
"</table>".
"";
}while($transaction = $results->fetch());
$data .= "</div>";
}
if($_REQUEST['module_MAIN'] == 'edittransactions'){
$data = <<<EOF
<div id="body">
<a href="index.php?module_MAIN=viewtransactions">View Transactions</a><br />
<a href="file:///home/thadeus/">notes</a>
</div>
EOF;
}
return $data;
}
}
?>
might be easier telling me how you do it instead of trying to 'fix' my system (which would work, just gets time consuming to post html into strings manually)
Thank you for your time!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: