Jump to content
xisto Community
Sign in to follow this  
leiaah

Blog Using Php: Files Or Mysql?

Recommended Posts

I've been planning to put up a blog on my site but I'm having trouble with how I should do it. I don't really know how blogs are made. Is it a database or a flat file? I know how to write to a file using PHP but I still don't know how to put the last entry on the top of the file. That's a big issue in the shoutbox I made for my site. If you look at it, the shouts keep appending at the end of the file and I want it to be on top.Can anyone help me please? It would be nice if you'd give me detailed instructions on how to put it up, with files or with MySQL.

Share this post


Link to post
Share on other sites

If you want a blog, I suggest that you use one of the systems available from your cPanel. Or some other already existing system you can upload to your account. Building your own blogging system from scratch can of course be fun if you're into that sort of thing and want to do loads of things with PHP (and perhaps MySQL).

Share this post


Link to post
Share on other sites

if you will just store blogs, you can just use flat files but for other stuff that has a high overhead such as login sessions, you better use mysql. but if you start to experience stuff like no read or write permission be of high overhead thats\'s the time you switch to mysql.

Share this post


Link to post
Share on other sites

MovableType is pretty neat in the way it builds static pages from your database. So when you post a new entry it builds a static index.html file, which doesn't need to get loads of things from your database.

Share this post


Link to post
Share on other sites

Hmm.. You could always use one of the blog things in the cPanel but if you want to make one from scratch, I could help you. I made one from scratch for my site.

<?phpmysql_connect('localhost,'DBUSER','DBPASS');mysql_select_db('DBNAME');?><html><head><title>My Blog</title></head><body bgcolor="#999999"><font color="black"><body><table border=".01"><tr bgcolor="#373737"><td align="center" colspan="10"><b><i>RETURN TO:</i> [LINKS TO OTHER PLACES</b></td></tr><form action="<?=$_SERVER['PHP_SELF']?>" method="POST"><tr bgcolor="black"><td><b><font color="white">Entry Title:</font></b></td><td><input type="text" name="blog_title" /></td></tr><tr bgcolor="white"><td><b>Entry Date:</b></td><td><input type="text" name="blog_date" /></td></tr><tr bgcolor="black"><td><b><font color="white">Current Mood:</font></b></td></td><td><input type="text" name="blog_mood" /></td></tr.<tr bgcolor="white"><td><b>Blog Entry:</b></td><td><textarea name="blog" rows="15" cols="30"></textarea></td></tr><tr bgcolor="black"><td><input type="submit" name="new_entry" value="Submit Entry!" /></td><td><input type="reset" value="Reset" /></td></tr></form></table><?phpif(isset($_POST['new_entry'])) {mysql_query("INSERT INTO blog SET title='{$_POST['blog_title']}',date='{$_POST['blog_date']}',mood='{$_POST['blog_mood']}',entry='{$_POST['blog']}'") or die(mysql_error());echo '<tr bgcolor="red" colspan="10"><td><b><font color="blue">Entry submitted.</font></b></td></tr>';} else {echo '';}?></body></font></font></html>SAVE THAT FILE AS blog.php--MySQL--CREATE TABLE `blog` (   `id` int(10) NOT NULL auto_increment,   `title` varchar(255) NOT NULL default '',   `date` varchar(255) NOT NULL default '',   `mood` varchar(255) NOT NULL default '',   `entry` text NOT NULL default '',   PRIMARY KEY(`id`))   TYPE=MyISAM;TO POST THE BLOG ENTRIES ON YOUR SITE<?phpmysql_connect('localhost','DBUSER','DBPASS');mysql_select_db('DBNAME');$query=mysql_query("SELECT title,date,mood,entry FROM blog ORDER BY id DESC");while($row=mysql_fetch_row($query)) echo '<table border=".01" align="center"><tr><td><b><big>'.$row[0].'</big></b></td></tr><tr><td><b>Mood:</b> '.$row[2].'</td></tr><tr><td>'.$row[3].'</td></tr><tr><td>---------------<br /><small><b>Posted On:</b> '.$row[1].'</small></td></tr></table>';?>^^PUT THAT ON THE PAGE YOU WANT THE ENTRIES TO SHOW UP ON


You should edit the bgcolors/colors because I made that in case your site did not run on a CSS.

if it did, include this under <head>

<link rel="stylesheet" type="text" href="STYLESHEETNAME.css" />


then edit the tables and <font color>s and <body bgcolor> and <tr bgcolor> tags.

Share this post


Link to post
Share on other sites

I work on one project and my aplication (Web PHP aplication) must work with txt files, because MySQL is not safe (losing and changing data). It's interesant, all forum is based on MySQL.If you want make blog from scratch, don't. Download any blog, and edit.

Share this post


Link to post
Share on other sites

Hmm..  You could always use one of the blog things in the cPanel but if you want to make one from scratch, I could help you.  I made one from scratch for my site.

 

<?phpmysql_connect('localhost,'DBUSER','DBPASS');mysql_select_db('DBNAME');?><html><head><title>My Blog</title></head><body bgcolor="#999999"><font color="black"><body><table border=".01"><tr bgcolor="#373737"><td align="center" colspan="10"><b><i>RETURN TO:</i> [LINKS TO OTHER PLACES</b></td></tr><form action="<?=$_SERVER['PHP_SELF']?>" method="POST"><tr bgcolor="black"><td><b><font color="white">Entry Title:</font></b></td><td><input type="text" name="blog_title" /></td></tr><tr bgcolor="white"><td><b>Entry Date:</b></td><td><input type="text" name="blog_date" /></td></tr><tr bgcolor="black"><td><b><font color="white">Current Mood:</font></b></td></td><td><input type="text" name="blog_mood" /></td></tr.<tr bgcolor="white"><td><b>Blog Entry:</b></td><td><textarea name="blog" rows="15" cols="30"></textarea></td></tr><tr bgcolor="black"><td><input type="submit" name="new_entry" value="Submit Entry!" /></td><td><input type="reset" value="Reset" /></td></tr></form></table><?phpif(isset($_POST['new_entry'])) {mysql_query("INSERT INTO blog SET title='{$_POST['blog_title']}',date='{$_POST['blog_date']}',mood='{$_POST['blog_mood']}',entry='{$_POST['blog']}'") or die(mysql_error());echo '<tr bgcolor="red" colspan="10"><td><b><font color="blue">Entry submitted.</font></b></td></tr>';} else {echo '';}?></body></font></font></html>SAVE THAT FILE AS blog.php--MySQL--CREATE TABLE `blog` (   `id` int(10) NOT NULL auto_increment,   `title` varchar(255) NOT NULL default '',   `date` varchar(255) NOT NULL default '',   `mood` varchar(255) NOT NULL default '',   `entry` text NOT NULL default '',   PRIMARY KEY(`id`))   TYPE=MyISAM;TO POST THE BLOG ENTRIES ON YOUR SITE<?phpmysql_connect('localhost','DBUSER','DBPASS');mysql_select_db('DBNAME');$query=mysql_query("SELECT title,date,mood,entry FROM blog ORDER BY id DESC");while($row=mysql_fetch_row($query)) echo '<table border=".01" align="center"><tr><td><b><big>'.$row[0].'</big></b></td></tr><tr><td><b>Mood:</b> '.$row[2].'</td></tr><tr><td>'.$row[3].'</td></tr><tr><td>---------------<br /><small><b>Posted On:</b> '.$row[1].'</small></td></tr></table>';?>^^PUT THAT ON THE PAGE YOU WANT THE ENTRIES TO SHOW UP ON
You should edit the bgcolors/colors because I made that in case your site did not run on a CSS.

 

if it did, include this under <head>

 

<link rel="stylesheet" type="text" href="STYLESHEETNAME.css" />

then edit the tables and <font color>s and <body bgcolor> and <tr bgcolor> tags.

60707[/snapback]


Thanks Mike! I'll try out the code! I figured I can make archives with these. :)

Share this post


Link to post
Share on other sites

Dude, chill out. I think it would be better to use my code since it's easier to understand (most likely) than your file is. I have a file as well. Two actually, one is the actual blog; the other is view_blog.php . It switches to view_blog.php?user=USERIDOFUSER . So each user on my site gets their own blog. :) Wait, where can I download your file though.. I want to check it out. I'll give you feedback. BTW- Did my code work?

Share this post


Link to post
Share on other sites

well just a thought... why don't you guys make use of template systems? so that your code will be easy to understand because it get rid of all tags in the script. it's also much efficient.

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
Sign in to follow this  

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