Jump to content

PHP+MySQL Unique Article Styling


SanTrapGamer
Go to solution Solved by gizmola,

Recommended Posts

First, I'm going to refer anyone reading this to the following links:

https://www.metagamevgc.com/articles

https://www.metagamevgc.com/team-reports

So, I'm looking into trying to re-create the content from these links with the help of php and MySQL, but what I've noticed is that the content under "Articles" don't seem to follow the same format and the same thing goes for the content under "Team Reports". Most of the content follow a similar structure and have similar main points they discuss, but from what I've researched so far on YouTube and Google is that you can't a singular template that can have variance to it based on the content of a database.

 

Taking for example the last two content posted under "Team Reports". They are similar in structure, but one includes many more images and more information than  the other one. So, in a single template wouldn't be sufficient for these two. Is there any way to replicate these using these, or do I have just use pure HTML to copy them?

Link to comment
Share on other sites

I really don't understand what your asking? Pulling data from a database and styling the HTML with CSS are totally different from each other. Take my website - https://phototechguru.com/ for example the Home Page and the Gallery Page uses the same data (they don't have to) and are obviously different in appearance. Those two links look the same to me? I don't see why you could not use the same template? You might have to make a few minor tweaks, but I don't think it would be anything drastic?

 

Here's the PHP for the gallery page:

        <?php
        $count = 0;
        foreach ($cms as $record) {
            echo '<div class="' . $displayFormat[$count] . '">';
            echo '<div class="gallery-item">';
            echo '<div class="images"><img src="' . $record['image_path'] . '" alt="Photo1" data-exif="' . $record['Model'] . ' ' . $record['ExposureTime'] . ' ' . $record['Aperture'] . ' ' . $record['ISO'] . ' ' . $record['FocalLength'] . '" width="800" height="534">';
            echo '</div>';
            $count++;
            echo '<div class="title">' . '<h1 class="pictureHeading">' . $record['heading'] . '</h1>' . '<span class="exifInfo">' . $record['Model'] . '</span>' . '</div>';
            echo '</div>';
            echo '</div>';

        }
        ?>

here's the PHP for the index page:

        <?php foreach ($cms as $record) { ?>
            <article class="cms">
                <img class="article_image"
                     src="<?= htmlspecialchars($record['image_path']) ?>" <?= getimagesize($record['image_path'])[3] ?>
                     alt="article image">
                <h2><?= $record['heading'] ?></h2>
                <span class="author_style">Created by <?= $record['author'] ?> on
                    <time datetime="<?= htmlspecialchars(CMS::styleTime($record['date_added'])) ?>"><?= htmlspecialchars(CMS::styleDate($record['date_added'])) ?></time>
                </span>
                <p><?= $record['content'] ?></p>
            </article>
        <?php } ?>

Pretty darn similar in my opinion and they are totally different looking pages.

Edited by Strider64
Link to comment
Share on other sites

Hello,

 

Thank you for your response. To clarify my question, let's use the two specific Team Report links below:

https://www.metagamevgc.com/team-reports/2020/12/16/the-calculated-run-a-top-16-players-cup-ii-team-report

https://www.metagamevgc.com/team-reports/2020/11/10/the-bird-and-the-mouse-a-collinsville-dual-team-report

The idea is to have MySQL setup with a database specifically for Team Reports that would utilize one singular HTML/PHP template. The overall main points are talked about in the articles: history of the team construction, a breakdown of the team and how to pilot the team. However, if you notice that length of content and images provided and even placement of images are different between the two of them. Is there someway to have a singular template connected to a single database that would result in creating the two articles linked here verbatim?

8 hours ago, Strider64 said:

I really don't understand what your asking? Pulling data from a database and styling the HTML with CSS are totally different from each other. Take my website - https://phototechguru.com/ for example the Home Page and the Gallery Page uses the same data (they don't have to) and are obviously different in appearance. Those two links look the same to me? I don't see why you could not use the same template? You might have to make a few minor tweaks, but I don't think it would be anything drastic?

 

Here's the PHP for the gallery page:

        <?php
        $count = 0;
        foreach ($cms as $record) {
            echo '<div class="' . $displayFormat[$count] . '">';
            echo '<div class="gallery-item">';
            echo '<div class="images"><img src="' . $record['image_path'] . '" alt="Photo1" data-exif="' . $record['Model'] . ' ' . $record['ExposureTime'] . ' ' . $record['Aperture'] . ' ' . $record['ISO'] . ' ' . $record['FocalLength'] . '" width="800" height="534">';
            echo '</div>';
            $count++;
            echo '<div class="title">' . '<h1 class="pictureHeading">' . $record['heading'] . '</h1>' . '<span class="exifInfo">' . $record['Model'] . '</span>' . '</div>';
            echo '</div>';
            echo '</div>';

        }
        ?>

here's the PHP for the index page:

        <?php foreach ($cms as $record) { ?>
            <article class="cms">
                <img class="article_image"
                     src="<?= htmlspecialchars($record['image_path']) ?>" <?= getimagesize($record['image_path'])[3] ?>
                     alt="article image">
                <h2><?= $record['heading'] ?></h2>
                <span class="author_style">Created by <?= $record['author'] ?> on
                    <time datetime="<?= htmlspecialchars(CMS::styleTime($record['date_added'])) ?>"><?= htmlspecialchars(CMS::styleDate($record['date_added'])) ?></time>
                </span>
                <p><?= $record['content'] ?></p>
            </article>
        <?php } ?>

Pretty darn similar in my opinion and they are totally different looking pages.

 

Link to comment
Share on other sites

  • Solution

Yes there is a way to do this, but it involves a solid foundational understanding of relational database design concepts and how to write code.  It would be a significant amount of work for a professional programmer.  An alternative to reinventing the wheel from scratch would be to use a php based CMS like Drupal or Bolt  These projects start you out with a lot of functionality and systems that already have templating, much of which can be tweaked without programming.  They also have "taxonomies" which are extensible.  You can utilize existing templates to learn how templating works, and how to customize them without already being an advanced developer.

Not to sound pessimistic here, but creating a blog database is not difficult at all, for something simple, but you still need to know what you are doing.  With that said, even though it might be fairly simple to do so, providing you a custom CMS database structure and instructions on how to create different templates against it is the topic of many an article, book and online course.   If you have a better idea of what approach you might take, people can provide you better advice.

Link to comment
Share on other sites

On 12/20/2021 at 12:36 AM, gizmola said:

Yes there is a way to do this, but it involves a solid foundational understanding of relational database design concepts and how to write code.  It would be a significant amount of work for a professional programmer.  An alternative to reinventing the wheel from scratch would be to use a php based CMS like Drupal or Bolt  These projects start you out with a lot of functionality and systems that already have templating, much of which can be tweaked without programming.  They also have "taxonomies" which are extensible.  You can utilize existing templates to learn how templating works, and how to customize them without already being an advanced developer.

Not to sound pessimistic here, but creating a blog database is not difficult at all, for something simple, but you still need to know what you are doing.  With that said, even though it might be fairly simple to do so, providing you a custom CMS database structure and instructions on how to create different templates against it is the topic of many an article, book and online course.   If you have a better idea of what approach you might take, people can provide you better advice.

This sounds like a solid answer. I'll definitely look into the information you've provided to see if it truly answers my question. Thank you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.