#131900 - 23/12/2002 14:33
Web site utility
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
Sorry for the help requests today, but I'm trying to add some stuff to my page. In that spirit:
I sort of want a blog-like program for my site. Unfortunately, all the applications on Sourceforge seem to be an all-site solution. I'd like something I might be able to sort of add to my existing home page as a column. I'm just looking for something simple that I can update in a "journal" fashion without downloading the pages and uploading them again, and have old messages automatically archived.
Has anyone used such a thing? I have support for PHP, perl, mysql, etc.
_________________________
Matt
|
Top
|
|
|
|
#131901 - 23/12/2002 14:45
Re: Web site utility
[Re: Dignan]
|
Pooh-Bah
Registered: 21/07/1999
Posts: 1765
Loc: Brisbane, Queensland, Australi...
|
can't you use PHP to do that to just part of the site? If you create a link to your blog area, it could be a separate 'sitelet' with php support for your entries.
Sorry, I'm no help.
_________________________
--
Murray
I What part of 'no' don't you understand?
Is it the 'N', or the 'Zero'?
|
Top
|
|
|
|
#131902 - 23/12/2002 16:08
Re: Web site utility
[Re: Dignan]
|
addict
Registered: 05/05/2000
Posts: 623
Loc: Cambridge
|
It would take about ten minutes to write that yourself and would really be just a few lines of code for the front-end and about a dozen in total for the admin system. Have a go - the best way to learn to program is to have a project with an aim; if you can handle JavaScript, then PHP is easy.
|
Top
|
|
|
|
#131903 - 23/12/2002 17:15
Re: Web site utility
[Re: Dignan]
|
veteran
Registered: 19/06/2000
Posts: 1495
Loc: US: CA
|
PHP with a MySQL backend - Very few lines of code, it will do exactly what you want, and you learn a little PHP. And, like David said, it's much easier to dive into something when you have a goal to aim for.
_________________________
Donato MkII/080000565 MkIIa/010101253 ricin.us
|
Top
|
|
|
|
#131904 - 23/12/2002 20:56
Re: Web site utility
[Re: Dignan]
|
carpal tunnel
Registered: 23/08/2000
Posts: 3826
Loc: SLC, UT, USA
|
Just use blogger or moveable type and do a Server Side Include for the column. Super easy and tons of features... especially if you use moveable type. I've been using it for years (underachievers.com)
|
Top
|
|
|
|
#131905 - 27/12/2002 20:14
Re: Web site utility
[Re: David]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
I've looked at the two suggestions made here.
I looked through the documentation for Moveabletype, and wasn't impressed. Plus it has more than I really need, so I'll just skip it for now.
This leaves me with learning a little PHP. That's cool. I've looked at the PHP site and through the introduction and did the examples they gave there. I like how easy it is to handle forms and such without creating a real program to handle them.
Now I have to figure out where to go from there. I don't, actually, know javascript. I keep trying and it never catches. I can get some of the basics, but it never seems to stick. I seem to be doing okay so far with PHP, but if you guys could give me a nudge into the direction that will help me do this little project, I'd appreciate it.
Thanks everyone.
*edit*
oh yeah, and I don't know anything about mySQL db's. Where do I learn about them?
Edited by DiGNAN17 (27/12/2002 20:15)
_________________________
Matt
|
Top
|
|
|
|
#131906 - 28/12/2002 07:54
Re: Web site utility
[Re: Dignan]
|
addict
Registered: 05/05/2000
Posts: 623
Loc: Cambridge
|
MySQL is made a lot easier if you don't have to fiddle with the command line or write much SQL. Go to http://www.phpwizard.net/projects/phpMyAdmin/ and download phpmyadmin. Just decompress it and put the directory in your webspace - it shouldn't need any more installation than that. If it complains, make sure the config file looks right.
You'll need a login and password for mySQL. Once you have that, you can create a database and a table. I'd suggest calling it article and having at least these four fields: id, timestamp, title, body. Then create a row and enter some test data.
Then create a PHP script with something along the lines of the following:
<?
mysql_connect ("localhost", "username", "password");
mysql_select_db("databasename");
$articles=mysql_query("SELECT * FROM article LIMIT 0,5");
while($article=mysql_fetch_array($articles) {
echo $article['title'].'<br>'.nl2br($article['body']).'<br><br>';
}
?>
That will list the first five article titles one per line. Just add a line within the while loop with echo $article['body'] to output the body of that article as well.
That should be enough to get you started.
|
Top
|
|
|
|
#131907 - 28/12/2002 08:50
Re: Web site utility
[Re: David]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
Thank you so much! Actually, my host has pre-installed phpMyAdmin, so I don't have to worry about that. They're a really good host, too (of course, they're British!!).
I'll see where I can get with that. You've given me a great start!
_________________________
Matt
|
Top
|
|
|
|
#131908 - 29/12/2002 20:35
Re: Web site utility
[Re: David]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
Sorry, but I tried just a basic test run of this code and it didn't work too well. I got this:
"Parse error: parse error in [path]/test2.php on line 10"
I think that's the line with the while loop. I don't see any problem with it. Is there? All I did was try a test of the script by placing that code in a file and running it on the server. Should I have done something else?
By the way, I can't seem to figure out how to create a row in mySQL and phpMyAdmin. I have a database and a table with the fields you suggested, but I can't find a way to add a row. (ps-what's the "id" field for?)
_________________________
Matt
|
Top
|
|
|
|
#131909 - 29/12/2002 20:54
Re: Web site utility
[Re: Dignan]
|
Anonymous
Unregistered
|
Hey dude, if you need some help with javascript just let me know.
|
Top
|
|
|
|
#131910 - 30/12/2002 00:55
Re: Web site utility
[Re: Dignan]
|
pooh-bah
Registered: 02/06/2000
Posts: 1996
Loc: Gothenburg, Sweden
|
ps-what's the "id" field for?
I'd put an auto-incrementing counter there - gives you a guaranteed unique key/id for each row (though a properly formed timestamp could serve the same purpose if you guarantee never to try multiple additions within the resolution of the timestamp format).
If you use american format for date and a text field for holding it (instead of a proper date/time field), a sequential id would also be good for sorting in actual entry order...
Not having played with MySQL myself, I'd imagine adding a row could be done in the same way as most any other SQL database:
INSERT INTO tablename (column1, column2, column3, etc) VALUES (value1, value2, value3, etc);
You need to list and give values for (at least) all required columns except the autogenerated ones (like autoincrementing counter)
/Michael
_________________________
/Michael
|
Top
|
|
|
|
#131911 - 30/12/2002 02:10
Re: Web site utility
[Re: Dignan]
|
veteran
Registered: 19/06/2000
Posts: 1495
Loc: US: CA
|
It's merely a syntax error, the exclusion of a closing parenthesis.
The line:
while($article=mysql_fetch_array($articles) {
Should read:
while($article=mysql_fetch_array($articles)) {
As for inserting into the table, Michael is correct. You can also use the phpMyAdmin interface to do the same.
_________________________
Donato MkII/080000565 MkIIa/010101253 ricin.us
|
Top
|
|
|
|
#131912 - 30/12/2002 07:40
Re: Web site utility
[Re: ricin]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
I did it!! I got it to work! Thanks, guys! I was a little confused on how exactly to insert in phpMyAdmin, but I figured it out. I also had to figure out what types to use for the various columns (CHAR, TEXT, etc.) but I got that too.
One problem now, David. The code you supplied goes through and outputs the first 5 rows of data. How do I output the last 5? I assume this is how I go about showing the most recent entries, right? I'll try to see if I can figure it out, though. I'll also try to figure out how to list entries from specific dates, so I can create archives
_________________________
Matt
|
Top
|
|
|
|
#131913 - 30/12/2002 08:27
Re: Web site utility
[Re: Dignan]
|
carpal tunnel
Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
|
"SELECT * FROM article ORDER BY timestamp DESC LIMIT 0,5"
_________________________
~ John
|
Top
|
|
|
|
#131914 - 30/12/2002 08:41
Re: Web site utility
[Re: Dignan]
|
veteran
Registered: 19/06/2000
Posts: 1495
Loc: US: CA
|
How do I output the last 5? I assume this is how I go about showing the most recent entries, right?
Assuming you setup the id field correctly, using auto_increment attribute, you can sort the data by id, in descending order and limit the output (say, again, to the last 5). Using a statement like the following (replacing the satement on the 5th line in the example):
"SELECT * FROM article ORDER BY id DESC LIMIT 0,5"
You can also sort by the timestamp field and yield the same results, as long as it is setup correctly.
I'll also try to figure out how to list entries from specific dates, so I can create archives
I'll start you out with a way to list entries from specific date ranges, as follows:
SELECT * FROM article WHERE timestamp >= 20021101000000 AND timestamp < 20021201000000;
This would return all records with a timestamp in the month of November.
If you need more information about the MySQL functions, this is a good place to start.
Hope that helps...Have fun.
_________________________
Donato MkII/080000565 MkIIa/010101253 ricin.us
|
Top
|
|
|
|
#131915 - 30/12/2002 09:00
Re: Web site utility
[Re: ricin]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
Thanks! And yes, this is very fun!
I did set up the id field correctly, and it auto-increments with each entry.
Thanks for the other tips, I'll try them out.
*edit*
ps- do you guys have any suggestions as to how I should handle the timestamps in regards to timezones? My host is located in England, so the times are all different from mine. Plus, when daylight savings time rolls around I'd have to change it. Any ideas?
Edited by DiGNAN17 (30/12/2002 09:02)
_________________________
Matt
|
Top
|
|
|
|
#131916 - 30/12/2002 09:03
Re: Web site utility
[Re: Dignan]
|
carpal tunnel
Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
|
Always set time to universal time and fix for local time zones only at display.
_________________________
Bitt Faulk
|
Top
|
|
|
|
#131917 - 30/12/2002 10:13
Re: Web site utility
[Re: Dignan]
|
addict
Registered: 05/05/2000
Posts: 623
Loc: Cambridge
|
In PHP/MySQL I always set timestamps in unix time ( time() ) - it makes it very easy to format into any notation (see the date() function) including allowing for time zone, is sequential by default and you can add and subtract seconds/hours/days/weeks/months very easily. Store it in an INT 11 field.
|
Top
|
|
|
|
#131918 - 30/12/2002 11:47
Re: Web site utility
[Re: David]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
Syntax question:
I am able to insert new data via a php script using this code:
values ('', '', 'this is the title', 'this is the body')
Now, how do I pass through variables that have been collected from a form. I tried this and got errors:
values ('', '', '$_POST["title"]', '$_POST["body"]')
I also tried it without the single quotes around the variables, but got errors.
I know this must seem funny, but I just don't know how to write this correctly yet.
_________________________
Matt
|
Top
|
|
|
|
#131919 - 30/12/2002 12:21
Re: Web site utility
[Re: Dignan]
|
addict
Registered: 05/05/2000
Posts: 623
Loc: Cambridge
|
Just use (title, body) VALUES ('$title', '$body'). You don't have to specify empty strings for fields you're not using or want to auto increment.
$_POST is the longhand. Just use the name of the form element as a variable. If you were using it, then you'd probably want to do '$_POST[title]' (or maybe "$_POST['title']"?) as you can't have single quotes within single quotes.
|
Top
|
|
|
|
#131920 - 30/12/2002 13:00
Re: Web site utility
[Re: David]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
Great! All worked out.
*edit*
oh wait, now the entries have no dates inserted. I was using the timestamp function in the column in phpMyAdmin, and that was working when I was inserting rows via the phpMyAdmin, but not now.
_________________________
Matt
|
Top
|
|
|
|
#131921 - 30/12/2002 13:41
Re: Web site utility
[Re: David]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
Okay, I've been messing around with the date() string. I made the timestamp field a normal text field like the title and the body, and just created a variable that is loaded with date() and the values I picked from that page.
Is this what you were talking about David? If so, I see no way to tell it what time zone I'm in. There are a few variables that will report how far out of GMT I am, but none that will get me there! argh.
_________________________
Matt
|
Top
|
|
|
|
#131922 - 30/12/2002 14:26
Re: Web site utility
[Re: Dignan]
|
addict
Registered: 05/05/2000
Posts: 623
Loc: Cambridge
|
What I was suggesting is that you store the unix timestamp in your database - eg 1041275715.
Then use the date() function to format it when you put it on the page. Always store your dates as GMT0 and then format it for your time zone when you display it on the page.
I've not worked with anything that required timezones before, but I guess you would just add or subtract the number of seconds for your timezone = eg do $timestamp-3600*8 when you pass it to the date() function. There might be a better or 'proper' way to do this; maybe within the date function itself? I haven't looked.
|
Top
|
|
|
|
#131923 - 30/12/2002 14:32
Re: Web site utility
[Re: David]
|
carpal tunnel
Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
|
Wow, do you guys have a UNIX epoch second clock on the wall at Empeg HQ?
|
Top
|
|
|
|
#131924 - 30/12/2002 14:36
Re: Web site utility
[Re: tonyc]
|
carpal tunnel
Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
|
perl -e 'print time()' is pretty quick and easy.
_________________________
Bitt Faulk
|
Top
|
|
|
|
#131925 - 30/12/2002 14:37
Re: Web site utility
[Re: wfaulk]
|
carpal tunnel
Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
|
True that, so are numerous online tools that do the same thing.. I just thought that of all places I'd expect a UNIX epoch second clock to be, Empeg HQ would be the most probable.
|
Top
|
|
|
|
#131926 - 30/12/2002 14:45
Re: Web site utility
[Re: tonyc]
|
carpal tunnel
Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
|
True. I wonder how difficult it would to build one, preferably synced with WWVB?
_________________________
Bitt Faulk
|
Top
|
|
|
|
|
|