Jump to content

Different way to do LAYOUT! (HTML + PHP)!

- - - - -

  • Please log in to reply
7 replies to this topic

#1
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
I was thinking today another ways to do simple html layout and got idea
I will use PHP variables and code layout then I can easily change everything on variables and make another site too!

HTML + PHP LAYOUT CODE:

<?php

//CSS part!

$style = 'body {

	background-color:#A4A4A4;

	}';

//CSS part ends!


//Head with CSS code and TITLE:

echo '<head><style>' . $style . '</style>

<title>Home</title>

</head>';


//text variables starts here:

$btext = '<h1>Welcome to my sites</h1>';

$ltext = '<a href="#">Links</a><br/><a href="#">Here</a>';

$ctext = '<p>OMG! Didnt even tought that you can create pages like this!</p>';

$ftext = '<p>Layout copied from W3Schools.com < visit !</p>';


//layouts variables starts here:

$table = '<table width="500" border="0">';

$banner = '<tr><td colspan="2" style="background-color:#FFA500;">' . $btext . '</td></tr>';

$linkbox = '<tr valign="top"><td style="background-color:#FFD700;width:100px;text-align:top;">' . $ltext . '</td>';

$contentbox = '<td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">' . $ctext . '</td></tr>';

$footer = '<tr><td colspan="2" style="background-color:#FFA500;text-align:center;">' . $ftext . '</td></tr></table>';


//Echo for the banner:

echo $table . $banner;


//Echo for the linkbox:

echo $linkbox;


//Echo for the contentbox:

echo $contentbox;


//Echo for the footer:

echo $footer;

?>

Layout is copied from W3Schools.com!

Just wanted to share this to newbies out there! There are many ways to do anything!
Trying them out is learning, so go ahead and start learning! :P

#2
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
Really your just echoing out variables, sorry to be critical but its basically what people have been doing with PHP from the start.
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#3
CatchMeTux

CatchMeTux

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Nothing's new.

#4
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
  • Programming Language:Java, C#, PHP
  • Learning:C, C++, C#, PHP, Transact-SQL, Assembly, Scheme

bbqroast said:

Really your just echoing out variables, sorry to be critical but its basically what people have been doing with PHP from the start.

Yeah and what is the point of using variables?
Why not just do:
<?php
echo "<h1>title</h1>";
?>


#5
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
Because normally those variables are from somewhere, for example a MySQL table. This allows you to rapidly develop a page without even glancing at the code.
Whats more is for example you could actually have every page on your website in the MySQL table and just have one page with a .htaccess redirect that passes the url of pages requested by a user. This URL is then matched with the content in the MySQL table and the content can be displayed.
With your example why not just:
<h1>title</h1>

Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#6
SoN9ne

SoN9ne

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
Forgive my rudeness but this is completely useless and an improper way to use PHP...
The is horrible advice to give a beginner because it is wrong.
It's more like a beginner's advice for beginners... which is the problem with most tutorial sites...

Putting HTML inside PHP, at least for this example( and most), is a complete waste of memory.
PHP is meant to work with HTML so storing HTML inside PHP is redundant to say the least... all you are doing is wasting memory for no apparent reason.
Asides from the horrible logic used in building the table (I'm not even going to ask why a table is even being used)... The same effect could be more efficiently done by using this code:
<?php

//text variables starts here:

$btext = 'Welcome to my site';

$ltext = array();

$ltext['#home'] = 'Link';

$ltext['#somewhereelse'] = 'Link2';

$ctext = 'OMG! Didnt even tought that you can create pages like this!';

$ftext = 'Layout copied from W3Schools.com < visit!';

?>

<head>

<style>

body {

    background-color:#A4A4A4;

}

</style>

<title>Home</title>

</head>

<body>

    <table width="500" border="0">

        <tr>

        	<td colspan="2" style="background-color:#FFA500;">

        		<h1><?php echo $btext; ?></h1>

    		</td>

    	</tr>

    	<tr valign="top">

    		<td style="background-color:#FFD700;width:100px;text-align:top;">

    		<?php

    		foreach ($ltext as $href=>$title) {

    		    echo '<a href="'.$href.'" alt="'.$title.'">'.$title.'</a><br />';

    		}

    		?>

    		</td>

    		<td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">

    			<p><?php echo $ctext; ?></p>

    		</td>

    	</tr>

    	<tr>

    		<td colspan="2" style="background-color:#FFA500;text-align:center;"><p><?php echo $ftext; ?></p></td>

    	</tr>

    </table>

</body>

The best advice would be to learn the basics of HTML and follow proper standards...
Building a webpage in a table is an old-school way of trying to have cross-browser compatibility; it is out-dated and is considered bad practice.
Use PHP for the dynamic content. Not the entire page. You are wasting memory and poorly using PHP.
Just because you can do something in PHP doesn't mean you should.
Read up on common practices and programming standards.
Better yet, read up on design patterns (MVC would be the best place to start as it is the most widely accepted design pattern).

Edited by SoN9ne, 03 October 2011 - 12:25 PM.

"Life would be so much easier if we only had the source code."

#7
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
OK GUYS! Seriously ! 1st. Yeah I was noob 2. I was bored.
Don't take these so .... like world going down now when noob posted bad post :33
There is going on huge fight, and lool D:
Just ... I dont know .. delete post or something, gettin tired when email spamming on meh :D
PLZ: Do not reply to my post :3

Young student from Finland!
PS: 15-year-old! :)


#8
SoN9ne

SoN9ne

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
No one is going to fight with you. It's just that this is in the tutorials so it's important to inform others this is not practical. Nothing personal, we all start somewhere and we all made these mistakes. It's all good :cool:
"Life would be so much easier if we only had the source code."




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users