Jump to content

Design / Code


zavin

Recommended Posts

I have always written my code and design in the same php file. All of my previous jobs have been small and did not have a need for a designer. Now I have a project that will require a designer to handle the layout and me to handle the coding. Does anyone have a good reference for a tutorial that I can use to help me divide the design portion from the code portion of my project. I am not looking for a script to do it for me, I am looking for a good example that will help me understand the right way to get started.

 

Any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/199558-design-code/
Share on other sites

Its really not that difficult. At its simplest, you need to retrieve your data from the database or whatever other business logic you need to use to retrieve data. Then store this data within an array or object, then include your template file.

 

Something like.....

 

<?php

if (isset($_GET['page'])) {
  $page = $_GET['page'];
} else {
  $page = 'default';
}
// connect to db

if ($result = mysql_query("SELECT title, content FROM articles WHERE page = '$page'")) {
  if (mysql_num_rows($result)) {
    $data = array();
    $data['page_title'] = $page;
    while ($row = mysql_fetch_assoc($result)) {
      $data['articles'][] = $row;
    }
    include 'template.php';
  }
}

 

Then, template.php might look something like....

 

<html>
  <head>
    <title><?php echo $data['page_title']; ?></title>
  </head>
  <body>
    <?php foreach ($data['articles'] as $article): ?>
    <div class="article">
      <h1><?php echo $article['title']; ?></h1>
      <p><?php echo $article['content']; ?></p>
    </div>
    <?php endforeach; ?>
  </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/199558-design-code/#findComment-1047444
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.