Database Driven Website

  HighTower 18:43 24 Feb 04
Locked

Has anyone created a database driven website before? My host supports asp, php and will give me a mysql database but I'm not sure how to set the whole thing up and query the database!

I want to create a website which will display text articles in the page from the text inputted in a database. I would rather not use Frontpage if possible as I am unfamiliar with it and don't like the way it works, I prefer Dreamweaver. I have good HTML skills but am new to all but the most basic of other programming. Any help would be appreciated.

Thanks

  Taran 18:56 24 Feb 04

Yes, I've coded more dynamic sites than I care to remember.

I'd ask you one question before we even try to go any further:

Do you actually need dynamic content for processes that you cannot do with standard static HTML or XHTML pages and form handlers ?

The reason I ask is that you've opened an enormous can of worms and there is no short and easy road to doing what you want to do.

I'd also mention that if your host supports ASP, PHP and MySQL you stick with PHP and MySQL. The ASP will be Chilisoft and let's not get started on that subject when you can use PHP.

Macromedia have some sample applications that demionstrate using Dreamweaver for dynamic content: click here

There are loads of links and a couple of books I could suggest but, I'd ask you to answer my question above first.

A full tutorial on data driven sites is way beyond the scope of this forum, but I will certainly help with specifics.

  HighTower 09:47 25 Feb 04

Thanks for your reply, you may remember I talked to you about creating forums a while back. Worked great, used phpBB2 so thanks for that.

Anyway, regarding database driven websites. It's something that I would like to know how to do for a couple of reasons, the first being curiosity, I'm not happy just sitting back on what I already know, I'd like to learn more! Also, the main reason is I will be developing a large site which is mainly information and text article driven so I figured that if I can separate the content from the design it may be advantageous long term should I wish to make any cosmetic changes to the whole site, rather than modify 100+ html pages. I also like the idea of being able to use the database with a search query for the site.

The client wants to update the site himself. Previously we have used Contribute which he really likes as it is very user friendly, but Contribute won't work on mySQL as I believe it prevents alteration of active coding.

What I would like is to basically create a page in html and in a cell where there would normally be directly inputted text I would like to call this text (and possibly an image or url of an image) from a database. I have been reading about php and mySQL and I agree with you, this seems to be the way to go.

I have a mySQL database already set up via my webhost and am running a forum on it, but I presume that I can just create a new table within the existing database and add information?

Any assistance you can give even to point me in the right direction would be appreciated.

Thanks.

  Taran 10:22 25 Feb 04

This comes hot on the heels of me asking what features people would like to see embedded in a small scale content management system !

click here

To begin with this is no small project by any stretch of the imagination and you may find some of the currently available portal systems or content management systems suitable to your requirements. Visit Sourceforge.net and search for 'portal' and 'content management' for more returns than you can shake a stick at.

I've played with lots of them and I've yet to find one I'd be entirely happy about using, which is why I'm coding my own now.

Two books I suggest you invest in to get you going:

Build Your Own Database Driven Website Using PHP & MySQL

By Kevin Yank

click here

and

PHP and MySQL Web Development, Second Edition, by Luke Welling and Laura Thomson

Kevin Yanks book is a good hand-holding guide to data driven sites. He bases the whole system around generating a Jokes site, where you create admin areas and upload scripts which allow you and selected users to add content to and view it from your MySQL database. As introductions to the subject go it's the best I've seen to date.

Far more advanced in scope and pitch is the second title I listed and it covers all kinds of everything: Content Management, XML web services, web based email, building forums, user authentication, e-commerce...

If you don't already have them I suggest that you download and install Apache, MySQL and PHP to use as a testing server on your own computer. An excellent article on doing just that can be found: click here

In fact, the same site has loads of tutorials and articles on PHP development in general so it is well worth scratching arout in there to see what you can dig up.

That should keep you out of mischief for a day or three !

It's a shame that you are discounting FrontPage. You can actually use some of the built-in form handling in FrontPage using the Server Extensions installed on your web host to write content to a database. at Its simplest this writes to a textfile, but you can also pull information back out of that textfile as well as put it in. Think about it...

The obvious strength of FrontPage is its excellent interaction via ASP with an Access database, but this requires a Windows IIS web host and a user who knows how it all works to begin with. I have to say that it is possibly far simpler than learning PHP and MySQL from scratch to use a point and click approach for most of the work and tweak the rest by hand in FrontPage. However, we are working to an Apache web host here so FrontPage is more or less out unless you want to migrate hosts.

Let me know if you need more.

Regards [and good luck]

Taran

  HighTower 11:50 25 Feb 04

Thanks a lot, I've read a couple of articles by Kevin Yank and was considering buying his book!

I noticed your post about your content management system, it was that which prompted me to post this subject as I figured you obviously know a lot about it.

I played with Frontpage for a bit, and I know that a lot of people like it, but I can't help but feel that it's kind of "cheating" a bit using the extensions and would rather learn how to do it properly from scratch. I also read somewhere that Access databases tend to not operate as well as mySQL in some cases, whether this is true or not I couldn't say! I also for some reason find Frontpage difficult to use, but that's probably just because I haven't given the time to learn it. If you think that Frontpage is genuinely a long term answer then I will certainly reconsider it.

Thanks again, off to buy a book!

  Taran 12:22 25 Feb 04

Access, in very general terms, should be thought of as a 10 concurrent user, 1 gigabyte of data system. As such it is more than adequate for a content management system and people who say one database is "better" than another tend to do so based largely on heresay or for specific tasks.

There are times when Access is fine and apropriate and other times when it isn't. Those other times do not necessarily mean that every man and his dog should migrate straight over to MySQL/PHP.

Many dynamic sites run using Cold Fusion [this forum for a start] while my area Police force are calling their pages via a Lotus Notes Database.

We haven't really the space to cover all the bases here, but the two most common systems for consumers are PHP/MySQL and ASP/Access and they wouldn't be in such widespread use if they both weren't up to the job. There are many other considerations as well, such as cost to provide from your host [PHP/MySQL on Apache is cheap and easy to provide], you ability to use the system and so on.

If you're learning from scratch and don't know any dynamic languages at all, I thnk PHP is easier than some others.

Much falls down to preference but I've seen a lot of people on a lot of forums say words to the effect that we should all be installing Linux so that we can run PHP, MySQL and Apache and 'benefit' from developing in a 'free' environment.

Hogwash.

Go with what you know and use your own abilities or preferences coupled with a 'best fit' solution based on the particular job at hand. I see no reason for radical changes in operating system nor do I see any convincing argument in favour of ASP/Access over PHP/MySQL and vice versa for a small scale content management system. If you wanted to code up something vast to manage huge corporate sites - I'm talking thousands of pages here - and you need intranet/extranet, FAQ features and so on you'd be using something different again.

If web hosts offered Windows IIS hosting with ASP/Access support for less than Apache/PHP/MySQL we'd all be sticking with ASP for common projects.

There is no "one fits all" solution and the day one comes along I think I'll bow out of web development for good.

  HighTower 18:12 26 Feb 04

I've ordered the book, should be here in a couple of days. In the meantime I've found a couple of chapters online which goes through setting the whole thing up.

At the moment I use a php script which in effect lets me query the mySQLdatabase from my web browser as you would from a command prompt. The script was written by Kevin Yanks and works great.

I can now enter info into the database and very basically can call information from a table into a web page aswell using php. Only issue I have at the moment is that any text I call is returned in my webpage with absolutely no formatting, just word after word after word, no line spaces and no paragraphs.

Any ideas to a workaround? Typically the info I retrieve would be around 5-6 paragraphs of maybe 60 words each. My table has three fields, a unique id number, the text, and the date.

  Taran 18:51 26 Feb 04

You need to call your content and output it wrapped in HTML to format it.

Pull a paragraph of text out of a database and you get a paragraph of text.

Wrap the text you pull from the database in HTML tags and you get formatted text.

This is a simple 'echo' example but a similar principle may be applied to your data driven content. Copy and pate this into Notepad and save it to your local server root folder as example.php then view it in your browser:

<html>

<head>

<title>Formatted Text wrapped in PHP</title>

</head>

<body>

<p><?php echo('This is a <b>test</b>!'); ?></p>

</body>

</html>


If you view the source code of the output you will see only HTML and you can obviously reference CSS files or format using XHTML as well.

  HighTower 09:43 27 Feb 04

I've tried your example above and have seen the desired result.

Forgive my ignorance, this is all very new, but how would I apply this principle to my database. For example, I have a field called "ArticleText" in a table in my mySQL database which contains a fair amount of text. Am I correct in thinking that I need to input the text of the article directly into the database unformatted and then apply the formatting after I retreive the text (through use of php) by wrapping it in HTML tags in the webpage?

I am using the following code to display the article:

<?php
define("SQL_SERVER", "myserver.xxxx.xxx");
define("SQL_UID", "my_user_name");
define("SQL_PWD", "my_password");
define("SQL_DB", "database_name");

$connection = mysql_pconnect(SQL_SERVER, SQL_UID, SQL_PWD);
mysql_select_db(SQL_DB, $connection);

$idname = "2";

$sql = "SELECT * FROM my_database WHERE id = '$idname'";
$result = mysql_query($sql);

$ID = mysql_result($result,0,"id");
$Text = mysql_result($result,0,"ArticleText");
$Date = mysql_result($result,0,"ArticleDate");

echo" $Text<br>Date = $Date<br>";

?>

As one of the fields in the table is a unique ID number this code returns the ArticleText of the ID number I specify in the script (in this instance it displays the text in the field "ArticleText" for entry id "2". (This probably isn't the best way to do it, but I've just been learning php for three days!).

In this case, how would I apply line breaks, paragraphs, font sizing etc to this text? Do I need to bring CSS in?

  Taran 14:06 27 Feb 04

I suggest that to begin with you keep things simple and wrap your above PHP into HTML code, along the same lines as I did above.

Save the file with a PHP extension and reference a stylesheet in it or place some style tages intot he page along these lines:

<html>

<head>

<title></title>

<STYLE TYPE="text/css">

<!--

CSS elements go in here

-->

</STYLE>

</head>

<body>

<?php

Your PHP database quesry goes in here

?>

</body>

</html>

We can get into how to run the commands from links and populate template pages later.

You're trying to run before you can walk and at the risk of making you step back a bit I'd suggest you spend some time playing with MySQL on its own from the command line. Once you can do all the MySQL basics at command line level you could try fooling around with it using phpMyAdmin.

Then, and only then, you could play with PHP and write some form handlers and general bits and bobs to get the idea of how it works on its own. In fact, using it for form handling is an excellent way to learn manhy of the functions you'll need later on and one of the many thigns PHP excels at is its form handling potential.

Then you put the two together.

If this sounds lke so much hand-holding and beneath you in any way, just about every book or serious educational course you will ever buy or take on the subject will follow a similar path to bringing you up to speed.

T

  HighTower 14:28 27 Feb 04

Yes. Patience never was my strong point but what you say makes sense. I'm starting to use command line prompts now on mySQL and suppose I'll have to wait until my book arrives before I delve much further into the subject!

I'll work on it and post back.

Thanks very much for your input.

This thread is now locked and can not be replied to.

How to get Windows 10 for free | How to install Windows 10: There is still a way to avoid paying…

1995-2015: How technology has changed the world in 20 years

Alex Chinneck’s giant ice cube Christmas tree at Kings Cross

Apple rumours & predictions 2017: The iPhone 8, new iPads, and everything else you should expect fr7…