Jump to content
xisto Community
Neutrality

Personal Blog [ Database Required ]

Recommended Posts

Okay, after a week, I have successfully created a personal web blog.
I first created it using a flat text file, I but realized that it was just too limited like that. So, I redid it in a database-compatible manner.

NOTES:

- This blog does not support comments yet. If you want, you can build  on this script by creating a comment system as well. I may also     update it with a comment system in the future.- You should have an average to intermediate knowledge of MySQL    commands and database manipulation in general, especially if you     want to add a comment system to it.- There are three files: BLOG.INC, ADDENTRY.INC, and MESSAGES.INC.

BLOG.INC/* Use this as an include in one of your webpages, preferrably not on  one visible to the public *//* Replace [ page url ] with the name of the page you want to send the data to [ ie. index.php ] */<?phpecho "<table width=100%>";echo "<form action=[ page url ] method='post'>";echo "<tr><td width=20%><font>Name:</font></td>";echo "<td width=80%><input type='text' name='name'></td></tr>";echo "<tr><td width=20%><font>Title:</font></td>";echo "<td width=80%><input type='text' name='title'></td></tr>";echo "<tr><td width=20%><font id='content1'>Message:</font></td>";echo "<td width=80%><textarea name='message'></textarea></td>      </tr>";echo "<tr><td colspan=2><center><input type='submit' name='blog'        value='Post!'></center></td></tr>";echo "</form></table><br>";?>

ADDENTRY.INC/* Use this as an include in the page that will be accepting this information *//* Substitute <server> with the name of the server [ which is usually "localhost" ], <username> with your database username, <password> with your database password, and <database> with the name of your desired database. */<?phpif(isset($blog)){     $dbase = mysql_connect (<server>, <username>, <password>);     mysql_select_db (<database>);      $todaysDate = getdate();     $date = $todaysDate[weekday]." ".$todaysDate[month]." ".             $todaysDate [mday].", ".$todaysDate[year];     $todaysTime = getdate();     $realHours = $todaysTime[hours] + 3;     $time = $realHours.":".$todaysTime[minutes].":".$todaysTime[seconds];     $createEntry = "INSERT INTO blog(id, name, title, message, date, time,       comments) VALUES(NULL, '$name', '$title', '$message', '$date',      '$time', 0)";      mysql_query($createEntry);     mysql_close($dbase);}?>

MESSAGES.INC/* Use this as an include in the page that will be displaying the Blog entries to the public *//* Substitute <server> with the name of the server [ which is usually "localhost" ], <username> with your database username, <password> with your database password, and <database> with the name of your desired database. */$dbase = mysql_connect (<server>, <username>, <password>);mysql_select_db (<database>); $dbase = mysql_connect ("localhost", "proxima_chris", "gh62jj");mysql_select_db ("proxima_myblog");  $findInfo = mysql_query("SELECT id, name, title, message, date, time,              comments FROM blog");for($n=mysql_num_rows($findInfo)-1; $n>=0; $n--){    mysql_data_seek($findInfo, $n);         list($id, $name, $title, $message, $date, $time, $comments) =          mysql_fetch_row ($findInfo);    echo "<table width=100% bgcolor=#000000 cellpadding=5 border=1          bordercolor=#444444><tr><td bordercolor=#000000 name='entry'>";    echo "<font>#".$id."</font>  ";    echo "<font>".$title."</font><br>";     echo "<hr width=100%></hr>";    echo "<font>".$message."</font><br><br>";    echo "<hr width=100%></hr>";    echo "<font>Posted by ".$name." on ".$date." at ".$time.         "</font><br>";    echo "</td></tr></table><br>";   }   mysql_close($dbase);   ?>

You have any questions, concerns, suggestions, or if you need further clarification/support feel free to post here and make yourself heard. I don't bite. :rolleyes:

Share this post


Link to post
Share on other sites

I second the template comment by stu. I just finished applying the new layout for my site, and if I had a template engine, it would have taken much less because the only thing I had to do when editing my pages was to move text around, and that took weeks.By the way, where can we see your new creation? What is its URL?

Share this post


Link to post
Share on other sites

I second the template comment by stu. I just finished applying the new layout for my site, and if I had a template engine, it would have taken much less because the only thing I had to do when editing my pages was to move text around, and that took weeks.

155723[/snapback]


If doing a redesign of a complete site PHP-Mesh is the way to go. You can change the layout without changing your original files! PHP-Mesh inserts code before and after all php/html pages and takes the html apart and puts it together again. You describe how to put your page back together again (i.e. the (new) layout) with one or more Decorator classes. A simple decorator would look like this:

 

<html>  <head>    <title>MySite :: <?php $page->title(); ?></title>    <?php $page->head(); ?>  </head>  <body>    <h1><?php $page->title(); ?></h1>    <?php $page->body(); ?>  </body></html>

In the above example all pages will get a title that starts with "MySite :: " and the title of the page is repeated in a H1 at the beginning. There's an $page object available in all Decorators, it contains methods corresponding to html-tags. Each method returns the contents from the original page. As the Decorators are just php files you can do all kinds of coding (like switching designs on certain pages).

 

It's awesome and seems like magic...

 

See http://forums.xisto.com/no_longer_exists/

 

The concept is based on SiteMesh, which does a similar thing for Java-based web sites.

Share this post


Link to post
Share on other sites

Yeah, I've seen software like that before. IPB uses that template system as well [ or at least I think it does ]. I could use something like that. Typing out all of those "echo" statements was hellish and tedious. I'll consider it.

Oh, and here is how the blog looks [ *NOTE: This is my website's blog, it's coded in the exact same way save for the stylesheet classes ]:

Neutrality's Blog

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.