PDA

View Full Version : My Blog



Ben Smith
April 4th, 2005, 08:33 AM
Sorry to go on about it, but I really need some help.

Here is what I need to know:
Done No. 1
2. About how to make a secure admin area for editing posts etc.
3. How to make it look better.
4. How to implement comments into it.
5. How to make the date and time of posting appear.

http://benji.voetsjoeba.com/blog

^ There it is ^

If it says some rubbish about Little Britain, thats where it's stretched, but if not I will post the permalink to it.

Thanks

Benji

Edit: I'm not plugging by the way, the link's just so you can see how much I have done. Will explain more of the code if required.

RabBell
April 4th, 2005, 08:51 AM
perhaps a CMS would be better (Content Management System)

It would help the look and security (I think), try Mambo

http://www.mamboserver.com/

Ben Smith
April 4th, 2005, 09:11 AM
Hmm, I'll look into that, thanks

The only danger with that is that:
1. I'm not on my own server so I don't wanna use up space
2. I will have to learn how to do everything again and input different stuff..

Thanks anyway, but I'd rather code it myself

nobody
April 4th, 2005, 10:15 AM
Comments work a lot like blog entries. What I do when I make blogs is create a table for entries with a new row for each entry with the text and date and poster and all, and also an auto incremented ID column. Then create a table for the comments, and have a column called like entryID or something that assigns the comment to that specific ID of the entry it belongs to. So each view page would then do a query like SELECT * FROM comments WHERE id = $id . You would want to get the id from a query string, or something of that nature.

Obviously you're going to have to figure out the particulars but that's at least a step in the right direction.

Here's one of my blogs to check out to see what I mean
http://www.xxviii.net/bawks/
So you click "follower" in any of the posts, and it'll take you to a viewEntry.php page, then you'll see the comments.

I hope that at least gives you an idea. Also this is all assuming you're using MySQL, but I don't see why you'd build a blog on anything else with php. :)

λ
April 4th, 2005, 10:31 AM
Comments work a lot like blog entries. What I do when I make blogs is create a table for entries with a new row for each entry with the text and date and poster and all, and also an auto incremented ID column. Then create a table for the comments, and have a column called like entryID or something that assigns the comment to that specific ID of the entry it belongs to. So each view page would then do a query like SELECT * FROM comments WHERE id = $id . You would want to get the id from a query string, or something of that nature.

Obviously you're going to have to figure out the particulars but that's at least a step in the right direction.

Here's one of my blogs to check out to see what I mean
http://www.xxviii.net/bawks/
So you click "follower" in any of the posts, and it'll take you to a viewEntry.php page, then you'll see the comments.

I hope that at least gives you an idea. Also this is all assuming you're using MySQL, but I don't see why you'd build a blog on anything else with php. :)

Yeah, that's the generally approved way of doing comments :)

For dates and times, you'll probably want to look at using UNIX timestamps (http://en.wikipedia.org/wiki/Unix_timestamp). PHP has some very nice functions for dealing with them, and you can store them in MySQL as a normal INT field ;)

xxviii, are you one of those people who constantly changes AIM? Because you never seem to be on "shu atsup" :P

nobody
April 4th, 2005, 10:33 AM
xxviii, are you one of those people who constantly changes AIM? Because you never seem to be on "shu atsup" :P

That's just one of many sn's actually. If I'm not on that one I'm usually on ratherlargefire :P

Ben Smith
April 4th, 2005, 10:34 AM
WOW, thanks...I just refreshed and a huge load came up! (I am currently updating the entries from the blog(s) I had before)

Thanks
Benji

By the way...keep on talking because I might need more help lol

Voetsjoeba
April 4th, 2005, 10:37 AM
Omega ... don't worry about the file size you're using, I've still got plenty of space left. If you don't hear from me, carry on ;)

Ben Smith
April 4th, 2005, 02:04 PM
ARGGG Help I really don't know how to do what XXVIII said

nobody
April 4th, 2005, 03:57 PM
What do you have done so far? It's a pretty simple concept, everything just ties back to ID's. If you've got some code or something for us to look at that would help.

Ben Smith
April 4th, 2005, 04:05 PM
I've done nothing! I'm so simple-minded the concept baffled me lol! ARG!
Could you talk me through it on AIM? (benjomg)
Edit: I've done something but it's real messy code...
Benji

nobody
April 4th, 2005, 04:10 PM
Well I really don't have the time to do it right now, so if you want a walkthrough on AIM it's going to be a few days. I can give you pointers and stuff though and nudge you along through the forums for the time being.

So first of all. Do you have a comments table set up in MySQL, and if so, what are the columns?

Ben Smith
April 4th, 2005, 04:12 PM
Yeah I do. The columns are:
commentID - for which comment it was
entryID - for which entry the comment was on
name - commenter's name
email - commenter's email
comment - the body of the comment

Thanks

nobody
April 4th, 2005, 04:15 PM
Okay you don't really need it to say commentID, I'd just use ID but if that's how you want to do it doesn't matter. Now is commentID set to auto increment and as it set as a primary key?

You also might want to throw in a date column and a time column, or you could just combine them in a datetime column, probably won't matter either way so that's up to you.

Now what you're going to want to do is put in a dummy row for testing purposes that you can delete later. Make the entryID correspond to a pre-existing entry ID.

Ben Smith
April 4th, 2005, 04:20 PM
Sorry I didn't get the corresponding bit...But yeah I've done the rest

By the way, this is the second time I've used MySQL so I dunno everything about it yet.

nobody
April 4th, 2005, 04:22 PM
Your entry, I'm assuming, is in a table all of it's own. Which I'm guessin also has ID's, correct? If that's the case, you just take one of those ID's and use it for the value of the entryID column in your comments table. That clear that part up at least?

Ben Smith
April 4th, 2005, 04:26 PM
Oh Right, just copy the ID's into the entryid column?

nobody
April 4th, 2005, 04:27 PM
Well just one of them is all. This is just for testing purposes.

Ben Smith
April 4th, 2005, 04:28 PM
Yeah done! Whenever we finish today, I am back on Thursday evening after tonight.

nobody
April 4th, 2005, 04:30 PM
Okay cool. So you're still here for a little while?

Anyway, do you have a single entry view page? For instance if you go to my old cruddy blog (www.xxviii.net/bawks) and click on any of the titles of the entires it'll take you to an entryView.php page. Do you have one of those?

Ben Smith
April 4th, 2005, 04:32 PM
Well I have an archive page which serves as it...it can be used as archive.php?id=1 for viewing the first post ever

nobody
April 4th, 2005, 04:37 PM
Okay cool! That's page is good enough for now. You might want to make a page that's almost identical to serve as your single entry view page, but this'll work.

Now what you want to do is have a mysql query that's something like this
SELECT * FROM comments WHERE entryID = $id
$id should be the same variable you use to get the $id from the query string.
Then you would just use an associative array to to fetch and display the data just as you do with entries.

Make senes?

Ben Smith
April 4th, 2005, 04:41 PM
I'm really sorry but do I just paste that in before the <HTML> tags? Or is it meant to go somewhere specific. $id being that same variable as what?! Is that just calling id the answer?

nobody
April 4th, 2005, 04:43 PM
Okay so how do you pull out your entries from the database. Do you do something like

while ($array = mysql_fetch_assoc($query) {

}

If so, it's the same exact concept as that for the comments.

Ben Smith
April 4th, 2005, 04:45 PM
$query_rsPosts = "SELECT body, `date`, topic, title, id FROM posts ORDER BY id DESC";
$query_limit_rsPosts = sprintf("%s LIMIT %d, %d", $query_rsPosts, $startRow_rsPosts, $maxRows_rsPosts);
$rsPosts = mysql_query($query_limit_rsPosts, $connBlog) or die(mysql_error());
$row_rsPosts = mysql_fetch_assoc($rsPosts);

It's from a Dreamweaver recordset

nobody
April 4th, 2005, 04:50 PM
okay so you want another variable like $query_rsPOSTS
except it should say

$query_rsComments = "SELECT * FROM comments WHERE entryID = $id";
$comments_query = mysql_query($query_rsComments);

That can go anywhere you want it to

Then you'd have something like

while($comments = mysql_fetch_assoc($comments_query){
echo $comments[comment];
}

And of course you'd echo everything and format it accordingly, but that's the general idea right there.

Ben Smith
April 4th, 2005, 04:51 PM
Ahhh...I'll try it right now

Ben Smith
April 4th, 2005, 04:59 PM
Nope. I can't get it working...shall I send you the source?

nobody
April 4th, 2005, 05:07 PM
Well first of all what kind of errors are you getting? And are you checking from the same entry that you put in the entryID column?

Ben Smith
April 4th, 2005, 05:13 PM
Well as I'm really baffled by this, I will post my source:

<?php require_once('Connections/connBlog.php'); ?>
<?php require_once('Connections/connBlog.php'); ?>
<?php
mysql_select_db($database_connBlog, $connBlog);
$query_rsComments = "SELECT * FROM comments WHERE entryID = $id";
$comments_query = mysql_query($query_rsComments);
$id = $rsPostList['id']
mysql_select_db($database_connBlog, $connBlog);
$query_rsLinkSidebar = "SELECT link, title, `desc` FROM sidebar ORDER BY id ASC";
$rsLinkSidebar = mysql_query($query_rsLinkSidebar, $connBlog) or die(mysql_error());
$row_rsLinkSidebar = mysql_fetch_assoc($rsLinkSidebar);
$totalRows_rsLinkSidebar = mysql_num_rows($rsLinkSidebar);

mysql_select_db($database_connBlog, $connBlog);
$query_rsAttachments = "SELECT attachdesc, attachlink, attachname FROM attachments ORDER BY attachid ASC";
$rsAttachments = mysql_query($query_rsAttachments, $connBlog) or die(mysql_error());
$row_rsAttachments = mysql_fetch_assoc($rsAttachments);
$totalRows_rsAttachments = mysql_num_rows($rsAttachments);

$maxRows_rsPostList = 5;
$pageNum_rsPostList = 0;
if (isset($_GET['pageNum_rsPostList'])) {
$pageNum_rsPostList = $_GET['pageNum_rsPostList'];
}
$startRow_rsPostList = $pageNum_rsPostList * $maxRows_rsPostList;

mysql_select_db($database_connBlog, $connBlog);
$query_rsPostList = "SELECT `date`, title, id FROM posts ORDER BY id DESC";
$query_limit_rsPostList = sprintf("%s LIMIT %d, %d", $query_rsPostList, $startRow_rsPostList, $maxRows_rsPostList);
$rsPostList = mysql_query($query_limit_rsPostList, $connBlog) or die(mysql_error());
$row_rsPostList = mysql_fetch_assoc($rsPostList);

if (isset($_GET['totalRows_rsPostList'])) {
$totalRows_rsPostList = $_GET['totalRows_rsPostList'];
} else {
$all_rsPostList = mysql_query($query_rsPostList);
$totalRows_rsPostList = mysql_num_rows($all_rsPostList);
}
$totalPages_rsPostList = ceil($totalRows_rsPostList/$maxRows_rsPostList)-1;

$maxRows_rsPosts = 2;
$pageNum_rsPosts = 0;
if (isset($_GET['pageNum_rsPosts'])) {
$pageNum_rsPosts = $_GET['pageNum_rsPosts'];
}
$startRow_rsPosts = $pageNum_rsPosts * $maxRows_rsPosts;

mysql_select_db($database_connBlog, $connBlog);
$query_rsPosts = "SELECT body, `date`, topic, title, id FROM posts ORDER BY id DESC";
$query_limit_rsPosts = sprintf("%s LIMIT %d, %d", $query_rsPosts, $startRow_rsPosts, $maxRows_rsPosts);
$rsPosts = mysql_query($query_limit_rsPosts, $connBlog) or die(mysql_error());
$row_rsPosts = mysql_fetch_assoc($rsPosts);

if (isset($_GET['totalRows_rsPosts'])) {
$totalRows_rsPosts = $_GET['totalRows_rsPosts'];
} else {
$all_rsPosts = mysql_query($query_rsPosts);
$totalRows_rsPosts = mysql_num_rows($all_rsPosts);
}
$totalPages_rsPosts = ceil($totalRows_rsPosts/$maxRows_rsPosts)-1;

$colname_rsSpecific = "-1";
if (isset($_GET['id'])) {
$colname_rsSpecific = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_connBlog, $connBlog);
$query_rsSpecific = sprintf("SELECT body, `date`, topic, title FROM posts WHERE id = %s", $colname_rsSpecific);
$rsSpecific = mysql_query($query_rsSpecific, $connBlog) or die(mysql_error());
$row_rsSpecific = mysql_fetch_assoc($rsSpecific);
$totalRows_rsSpecific = mysql_num_rows($rsSpecific);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- TemplateBeginEditable name="doctitle" -->
<title>Work in Progress</title>
<!-- TemplateEndEditable --><link href="/style.css" rel="stylesheet" type="text/css">
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>

<body>
<center>
<table width="560" height="1014" border="0" cellspacing="2">
<tr>
<td id="header" width="400"><div align="center">This is a test header </div></td>
<td height="28" width="138" class="styleselect"><div align="center">Navigation</div></td>
</tr>
<tr>
<td width="400" rowspan="7" align="left" valign="top" nowrap><!-- TemplateBeginEditable name="Main" --><span class="blogtitles">Blog<br>
<hr>
</span>
<table width="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="178" class="blogtitles">&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td colspan="4"><div align="right" class="aboutmetitle">
<div align="left"><span class="blogtitles"><?php echo $row_rsPosts['title']; ?></span></div>
</div></td>
</tr>
<tr>
<td colspan="4" class="entrybody"><div align="right"> <span class="aboutmetitle">Posted On: <?php echo $row_rsPosts['date'];?><br>
In:<?php echo $row_rsPosts['topic']; ?><br>
By: Ben</span></div></td>
</tr>
<tr>
<td colspan="4" class="entrybody" ><?php echo $row_rsPosts['body']; ?><br>
</td>
</tr>
<tr>
<td colspan="4" class="entrybody" ><div align="right" class="aboutmetitle">Read comments (<?php echo $comments ?>)</a> </div></td>
</tr>
<?php } while ($row_rsPosts = mysql_fetch_assoc($rsPosts)); ?>
<?php } while ($comments = mysql_fetch_assoc($comments_query))?>
</table>
<!-- TemplateEndEditable --></td>
<td width="150" height="159" class="aboutme"><div align="left" class="aboutmetitle">
<div align="center">
<p>About Me</p>
</div>
</div>
<dt class="img"><img src="images/me.png" alt="Me in Dartmouth - March/April 05" width="63" height="66"></dt>

<div align="left">Ben Smith<br>
Swindon<br>
Wiltshire<br>
England<br>
UK
</p>
<br>
<br>
<hr>
</div></td>
</tr>
<tr>
<td width="150" height="159"><div align="left" class="aboutmetitle">
<div align="center"><p>The Playlist</p></div>
</div>
<dt class="img"><img src="images/mp3player.gif" alt="Xclef MT-500 MP3 Player" width="68" height="50"></dt>
<div align="right" class="mp3s">
<div align="center"><br>
Coming Soon </div>
<br>
<br>
<br>
<hr>
</div></td>
</tr>
<tr>
<td height="112" width="150" class="aboutme"><div align="center">
<p class="aboutmetitle">Contact me</p>
</div>
<div class="aboutme">
<div align="center"><a href="mailto:ben.e.smith@gmail.com" title="ben.e.smith@gmail.com">Send me an email</a><br>
<a href="/ben.vcf" title="Like a contact card">Download my vCard</a><br>
<br>
<hr></div>
</div></td>
</tr>
<tr>
<td width="150" height="102" class="aboutme"><div align="center">
<p class="aboutmetitle">Other Sites</p>
<p class="aboutme">

<table border="0" cellpadding="0" cellspacing="0">
<tr>
</tr>
<?php do { ?>
<tr>
<td><div align="center"><a href="http://<? echo $row_rsLinkSidebar['link']; ?>" title="<? echo $row_rsLinkSidebar['desc']; ?>"><?php echo $row_rsLinkSidebar['title']; ?></a></div></td>
</tr>
<?php } while ($row_rsLinkSidebar = mysql_fetch_assoc($rsLinkSidebar)); ?>
</table>
<br>
<hr>
</div></td>
</tr>
<tr>
<td width="150" height="192" class="aboutme"><p class="aboutmetitle" align="center">Archive Options </p>
<p class="aboutmetitle" align="center">Last 5 Posts</p>
<center><table border="0" cellpadding="0" cellspacing="0">
<tr>
</tr>
<?php do { ?>
<tr>
<td><a href="archive.php?id=<?php echo $row_rsPostList['id']?>" title="<?php echo $row_rsPostList['date']?>"><?php echo $row_rsPostList['title']; ?></a></td>
</tr>
<?php } while ($row_rsPostList = mysql_fetch_assoc($rsPostList)); ?>
</table>
<p class="aboutmetitle">Select by month</p>
Coming Soon!
<hr>
</center></td><br>
</tr>
<tr>
<td width="150" height="96" class="aboutme"><div align="center">
<p class="aboutmetitle">Attachments</p>

<table border="0" cellpadding="0" cellspacing="0">
<tr>
</tr>
<?php do { ?>
<tr>
<td><a href="http://<? echo $row_rsAttachments['attachlink']; ?>" title="<? echo $row_rsAttachments['attachdesc']; ?>"><?php echo $row_rsAttachments['attachname']; ?></a></td>

</tr>
<?php } while ($row_rsAttachments = mysql_fetch_assoc($rsAttachments)); ?>
</table><br>
<hr>
</div></td></tr>
<td height="122" width="150" class="aboutme"><p class="aboutmetitle" align="center">Gadgets</p>
<p align="center">
<a href="http://jigsaw.w3.org/css-validator/">
</a><a href="http://jigsaw.w3.org/css-validator/check/referer" title="CSS Validator"><img src="images/cssvalid.png" alt="This site is CSS Valid" width="80" height="15" border="0" class="aboutme"></a>
<br>
Made for Firefox
<hr>
</td>
</tr>

<tr>
</tr>
<tr>
<td class="footer" width="400">Copyright &copy; Ben Smith 2005-6. All Rights Reserved | <a href="admin.php" class="hidden">Admin Login</a> </td>
<td height="42" width="150" class="aboutme"><div align="center">Powered by:<br>
Dreamweaver MX 2004</div></td>
</tr>
</table>
</center>
</body>
</html>
<?php
mysql_free_result($rsAttachments);

mysql_free_result($rsPostList);

mysql_free_result($rsPosts);

mysql_free_result($rsSpecific);

mysql_free_result($rsLinkSidebar);
?>

Ben Smith
April 4th, 2005, 05:16 PM
I've got to go. Thanks very much for your help.
Can we continue later in the week? Thursday/Friday?
Anyway, I'll probably be on AIM/MSN when I'm back.
Bi

nobody
April 4th, 2005, 05:21 PM
Just put this where you want the comments



$query_rsComments = "SELECT * FROM comments WHERE entryID = $id";
$comments_query = mysql_query($query_rsComments);
while($comments = mysql_fetch_assoc($comments_query){
echo $comments['comment'];
}


That'd be on the archive.php page. Go to the entry that has the same entryID you put in before. That really should work. Also change the ['comment'] part to the appropriate name if it's different.

nobody
April 4th, 2005, 05:23 PM
Woops didn't see your last post, sure we can continue whenever =)

Ben Smith
April 5th, 2005, 01:29 PM
Sorry to say I was going when I actually wasn't. We were going camping, but we were not allowed without an adult!
So I'm back and I will be here all week...

Ben Smith
April 5th, 2005, 02:03 PM
Well the code you gave me didn't work, so I think I might need to handcode this blog instead of using Dreamweaver's wizards...don't you think?
I might even start fresh because I'm not too happy with the actual layout...I am running low on inspiration at the moment though.

nobody
April 5th, 2005, 06:46 PM
Oh heck ya dude. I didn't know you were using dreamweavers wizards, that would explain your wierdo code. Definitely start from scratch, you'll have a much much better idea of what's going on. It's not hard at all really once you get into it.
Good luck :0

iloveitaly
April 5th, 2005, 10:01 PM
Just wondering, but why dont you use a pre-made blog like wordpress? If you just want the novelty of having your own blog that you youself coded then i understand :)

hl
April 5th, 2005, 10:52 PM
adding to iloveitaly's comment, there are a lot of tutorials for doing stuff like this

Ben Smith
April 6th, 2005, 05:22 AM
Yeah, thanks Hlall I will Google it once I get the styles done. I will put together the stylesheet in Dreamweaver as it's the best I've got...

@ Iloveitaly > Yeah I want to make my own, I don't know why. Lol...I suppose it is quite cool to see something you've made working...

@xxviii > Thanks for the well-wishing and the help...I appreciate it and I'm sorry to have wasted your time

Ben Smith
April 6th, 2005, 01:14 PM
Hmm...I'm stuck...again ;)

I was trying to make the TV and Book list on my blog appear. As you know I am sworn not to use the Dreamweaver wizards.

I have used this code as the connection

<?php
$connect = mysql_connect("localhost", "voetsjoe_benji", "MY PASSWORD");
mysql_select_db("voetsjoe_benji", $connect);
$tvbresult = mysql_query("SELECT * FROM tvbooklist ORDER BY id ASC");
?>

And that should connect and extract the data. The next block of code is to loop and display the data.

<div class="menu_item"><span class="menu_subtitles">Book/TV List</span><br>
<a href="http://<?php echo $tvbrow['link'];?>" title="<?php echo $tvbrow['desc'];?>">
<?php while ( $tvbrow = mysql_fetch_array($tvbresult) ) {
echo($tvbrow['title'] . "<br>");
}
?>
</a></div>
That does display the items (all 2 of them), but I'm trying to get the links from the SQL db. The items all seem to be as one when I hover over them...and the dynamic link attribute doesn't work anyway...

Thanks
Benji

DON'T WORRY ABOUT ANSWERING, I DID IT