Jump to content

Recommended Posts

Most of the websites I have built have not been large and not dynamic in nature, but I need to make one now with a boatload of content on it. and I’m needing a little resource help where I can research something. I’m sure all developers do this, and I know I need a massive database or 2 and the PHP knowledge I already have, but I’m just looking for a little guidance about how to do this the easiest way. It may actually sound like a stupid question and I might be over-thinking a bit. So…

Lets say I have 500 articles that I want to make available to a site visitor and give them the option to choose what they want to look at through nav menus and submenus. I want the same page to display to the user, regardless of what article is chosen.  how does PHP play a part in that? Would I be right by saying the following?

If the home page had this content on it:

This website is a course in PHP coding. <a href="courseTemplate.php" target="_blank">Click here</a> to view course #1.

and I wanted all the course content to be displayed through the use of the “courseTemplate.php” file, how simple is that? I would assume that these types of things would be the results and the techniques to accomplish the goal, right?

=> a resulting URL that looks like this:

www.site.com/courseTemplate.php?id=1

=> storing all the text of the course material in one single field of a DB record. NOT storing the layout-oriented code (HTML, etc.) and echoing it out with the rest of the text.

=> making use of the GET() function somehow to pull the course’s text content out of the database.

Can someone show me a website that demonstrates this? I don’t think this is very difficult, and I’m sure there are web resources available that show how this is done. I’m almost sure that most news agency websites do this, and I know for a fact that most forum software has this template technique written into it, regardless if SEO is included or not. Sorry for the basic nature of this question. I know some of my previous posts have been such where I’ve asked much more difficult questions than this. I have seen youtube tutorials on issues similar to this, but nothing pulled up by google really shows this in a very simplistic nature. thanks.

Virtually every single website on the internet works like this. In fact it's such a common thing, you should try looking for a tutorial on how to use PHP and databases, because one of those will cover the URL stuff automatically.

$_GET (which is a variable, not a function) can give you the ID. You do a database query to find the information according to that ID. If found, you grab the data and display it on the page. (If not, you do something appropriate.)

thanks req.  just a follow up question here if you don't mind.  Is front end code ever stored in a database and echoed out with server side code like PHP, along with plain text content like what I'm talking about in my previous post?  so for instance, according to professional programming standards, would doing something like this ever be needed?  either that, or would there ever be a reason to do it?

DB content in field 1:

<h1>PAGE HEADER</h1>
  <p>
    This is article 1's first paragraph of text.
  </p>
    <ul>
      <li><a href="image.jpg" target="_blank">CAPTION</a></li>
    </ul>

code on the page:

<?php
$var = $_GET operation here to get above content;
echo $var;
?>

 

31 minutes ago, ajetrumpet said:

thanks req.  just a follow up question here if you don't mind.  Is front end code ever stored in a database and echoed out with server side code like PHP, along with plain text content like what I'm talking about in my previous post?  so for instance, according to professional programming standards, would doing something like this ever be needed?  either that, or would there ever be a reason to do it?

It's rare. It has some significant problems, and is only really excusable when you have absolutely no other choice. And there's always another choice.

For the most part you should be storing the content in a representation-agnostic way. Meaning no HTML. For example, Markdown is popular because it allows an author to dictate structure (like headings and lists) without saying exactly what they look like. An application can then render the Markdown into whatever actual format, like HTML or RSS. Markdown is also a lot easier for non-technical people to read and write, and unlike HTML a malicious author cannot write anything that could compromise the website hosting the content.

Your example could be written as

# Page Header

This is article 1's first paragraph of text.

* ![some image](image.jpg "CAPTION")

Side note: the page header should be separate from the content - you'll want it for <title>s and tables of content and other things. You can render it yourself easily enough.

Even XML would be better than HTML (but it's not as easy to write). There are actual standards for this, but I'm too lazy to look them up for an example so

<?xml version="1.0" encoding="utf-8"?>
<content>
	<paragraph>This is article 1's first paragraph of text.</paragraph>
	<numbered-list>
		<item>
			<image src="image.jpg" caption="CAPTION" />
		</item>
	</numbered-list>
</content>

You can transform XML into HTML with two steps: the first is writing a specific thing that an XML translation library understands (difficult) and the second is writing a bit of PHP code to perform the translation (easy). I did this once years ago as an experiment for a website. Rather fun.

thanks man.  I don't think I have any interest in delving into XML transformations, as it seems like your first example would be an easier way to do this.  I took a look here:  https://en.wikipedia.org/wiki/Markdown#Example

the only other question I suppose I have about this whole thing, is if content in the db record looks like this:

# Page Header

This is article 1's first paragraph of text.

* ![some image](image.jpg "CAPTION")

then wouldn't that require an extensive amount of application coding to decipher the symbolisms and transform them into actual rendered HTML during the request?  per the wiki article example, there are many symbolisms involved to indicate what an author would want.  does the code required for this type of transformation have to be written from scratch all the time, or have there been tools developed already that can make that process easier?  I suppose this article would be a great example of how a markdown process and database querying could be used?  This page looks like what I'm talking about.  content printed out onto a template layout page:

https://www.thestreet.com/investing/bitcoin-scams-14640202

Edited by ajetrumpet
1 hour ago, ajetrumpet said:

does the code required for this type of transformation have to be written from scratch all the time, or have there been tools developed already that can make that process easier?

Good question.

I think I've got pretty much everything I need here.  thanks for letting me bother you about this.  😃  I'll keep feeding my curiosity about whether or not you are retired and just passing on knowledge for the enjoyment of it like @Barand

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.