TinyPortal

Development => Block Codes => Topic started by: bloc on October 29, 2005, 01:25:30 AM

Title: "Today in History" block
Post by: bloc on October 29, 2005, 01:25:30 AM
Here is a block that will show "today in history" - the sql data file kindly provided by clickbouyow.

Pretty straightforward - just insert the code into a phpblock and adjust accordingly:
$my_height = set this to number of lines before it will have a scrollbar..some texts are very long. :)
import the sql file in the attached zip-file to your database. If you do not, it will give an database error.


$my_height = 15;
$today = mktime();
$today_day = date("j", $today);
$today_month = date("n", $today);

$request = db_query("SELECT pn_yid, pn_content FROM nuke_ephem WHERE pn_did=$today_day AND pn_mid=$today_month ORDER BY pn_yid ASC", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
{
echo '<div style="height: '.$my_height.'ex; overflow: auto;">';
while($row = mysql_fetch_assoc($request)){
echo '<b>' . $row['pn_yid'] . '</b> - ' . $row['pn_content'] . '<br />';
}
                echo '</div>';
mysql_free_result($request);
  }


[attachment deleted by admin]
Title: Re: "Today in History" block
Post by: clickbouyow on October 29, 2005, 02:16:34 AM
Excellent!  Thanks Bloc!  Works like a charm!
Title: Re: "Today in History" block
Post by: JayBachatero on October 29, 2005, 03:19:47 AM
nice block.  you should enable it here.  it would be a nice feature.
Title: Re: "Today in History" block
Post by: eldacar on October 29, 2005, 04:32:35 AM
It would be interesting to see if it could be taken from something like http://en.wikipedia.org/wiki/October_29 instead of the database table (which wouldn't be updated).
Title: Re: "Today in History" block
Post by: bloc on October 29, 2005, 08:52:09 AM
It could be done if they had a xml feed, or rss/rdf.. ;)
Title: Re: "Today in History" block
Post by: mastroale on October 29, 2005, 09:49:56 AM
Great block! thanks!
Title: Re: "Today in History" block
Post by: crip on October 29, 2005, 01:59:41 PM
Thanks Bloc..

now may-be I can learn some history. ;)

crip~
Title: Re: "Today in History" block
Post by: Skhilled on October 29, 2005, 04:51:30 PM
This is a great block but can you add your own days in history to it? Or even delete certain ones? Some people might want to remember certain things while others might want to forget some...
Title: Re: "Today in History" block
Post by: bloc on October 29, 2005, 05:46:34 PM
Its all in the database tables..so you need to add or delete there. To administrate it through otherwise you would need a separate script.

If the table was expanded with an extra "on/off" field, you could even add/remove and turn off existing ones, either for all members or selected membergroups. ;)
Title: Re: "Today in History" block
Post by: Skhilled on October 30, 2005, 01:53:14 AM
Thanks, Bloc!
Title: Re: "Today in History" block
Post by: Moocat on October 30, 2005, 04:28:19 AM
very nice, bloc :) i love it
Title: Re: "Today in History" block
Post by: crip on October 31, 2005, 12:16:00 PM
Could someone try to explain to me  :uglystupid2: ..exactly where and how to import this to DB?..I've tried importing this several times and I getting syntax errors because I do not know what I'm doing..and my Cpanel doesn't say much about import / export.

Thanks,
crip~
Title: Re: "Today in History" block
Post by: bloc on October 31, 2005, 12:47:00 PM
Use phpMyAdmin to import it. Have you used that before?
Title: Re: "Today in History" block
Post by: Moocat on October 31, 2005, 02:39:31 PM
i had to do this just recently when i switched hosting. go to your cpanel and select mySQL databases. then at the bottom hit phpmyAdmin. from there it's rather simple, and there's a nice long post from grudge on how to do it here (http://www.simplemachines.org/community/index.php?topic=15252.0)
Title: Re: "Today in History" block
Post by: bzmorrow on October 31, 2005, 05:57:16 PM
Simple machines sure is slow today, they running that site from a dialup connection?

I dont see any import anything in phpmyadmin, I do see export but that not gonna help I have done it once before but I cant remember where I did it at. It seems to my like once you go into myadmin it was at the top to import?

Oh well I will keep trying, I didnt read this part orginally hosed a whole install...I guess its important. internal server errors, no way to get back in.....:(
Title: Re: "Today in History" block
Post by: graffixjones on October 31, 2005, 06:27:31 PM
In phpMyAdmin, first select your database in the pop-up at the left-hand side of the window.  Then, click the little 'SQL' tab at the top of the window.  Underneath the SQL text field, there should be a table labeled 'Or, location of the text file'.
Click the 'Choose File' button, select the .sql file you downloaded in the first post, and then click 'Go'.
Voila! :)

This is a cool little block, but I'm having trouble with it 'underlapping' the block below it.
Attached is a screenshot of what I'm talking about... it could just be how Safari handles the css.  An easy enough fix is just to make sure it's the last block on the sidebar, but I was hoping there was another way to fix it so I can keep it in it's current position.
Title: Re: "Today in History" block
Post by: bloc on October 31, 2005, 06:44:32 PM
this code...

echo '<div style="height: '.$my_height.'ex; overflow: auto;">';
while($row = mysql_fetch_assoc($request)){
echo '<b>' . $row['pn_yid'] . '</b> - ' . $row['pn_content'] . '<br />';
}
echo '</ul>';
mysql_free_result($request);


..actually had an error in there. I have changed the post now, so it says:
echo '<div style="height: '.$my_height.'ex; overflow: auto;">';
while($row = mysql_fetch_assoc($request)){
echo '<b>' . $row['pn_yid'] . '</b> - ' . $row['pn_content'] . '<br />';
}
mysql_free_result($request);


Does that solve the problem?
Title: Re: "Today in History" block
Post by: graffixjones on October 31, 2005, 06:52:47 PM
Unfortunately, no. :(

It's probably a Safari bug... the rest of the blocks work fine...

However, I was able to echo in some table settings for the block

echo '<table width="100%" border="0"><tr><td>';
//the block code//
echo '</td></tr></table>';


And now it works fine in any position... thanks for looking into it though, I appreciate it.
Title: Re: "Today in History" block
Post by: bloc on November 01, 2005, 10:17:19 AM
Must be the div that confuse Safari. When in doubt, use a table... :)
Title: Re: "Today in History" block
Post by: winrules on November 01, 2005, 01:17:57 PM
I've had the same problem with it messing up the block under it, but in IE6. Adding the table thing worked for me, too though

So it's not just safari
Title: Re: "Today in History" block
Post by: crip on November 04, 2005, 02:55:15 PM
Same ERROR everytime I run it.

MySQL said:ÂÃ, 

#1064 - You have an error in your SQL syntax.ÂÃ,  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'PK' at line 1
Title: Re: "Today in History" block
Post by: bloc on November 04, 2005, 05:20:43 PM
Did you import the sql file into the database?
Title: Re: "Today in History" block
Post by: crip on November 04, 2005, 05:22:47 PM
Yes, but I get that same error everytime?..

It also tells me on the Forum that no table was found for it...
Title: Re: "Today in History" block
Post by: bloc on November 04, 2005, 05:42:37 PM
maybe the table didn't upload correct. Its a big table. Have you tried to repair the nuke... table?
Title: Re: "Today in History" block
Post by: crip on November 04, 2005, 05:51:57 PM
I didn't see that repair option with in the error page .. we have the same Host.. AH..you probably no more about that cool Cpanel than myself. :) ...

I will try again though thank you Bloc.
Title: Re: "Today in History" block
Post by: bloc on November 05, 2005, 08:25:24 AM
I am not sure how well you know cpanel..but if you click on Mysql icon in cpanel, then scroll down to "phpMyadmin" - a small link at the bottom - you can check the tables. First off is to see you actually have a table named "nuke_ephemerid" - and second: mark it and choose at the bottom "repair table".

Same host..you use artichost ? :)
Title: Re: "Today in History" block
Post by: Nokonium on November 05, 2005, 06:35:59 PM
Quote from: Bloc on October 29, 2005, 08:52:09 AM
It could be done if they had a xml feed, or rss/rdf.. ;)

I came across this on the BBC website (http://news.bbc.co.uk/onthisday/bsp/rss.stm?rss=http://news.bbc.co.uk/rss/on_this_day/front_page/rss091.xml) Do other news channels etc do similar?
Title: Re: "Today in History" block
Post by: houston on November 05, 2005, 06:39:04 PM
Quote from: nokonium on November 05, 2005, 06:35:59 PM
Quote from: Bloc on October 29, 2005, 08:52:09 AM
It could be done if they had a xml feed, or rss/rdf.. ;)

I came across this on the BBC website (http://news.bbc.co.uk/onthisday/bsp/rss.stm?rss=http://news.bbc.co.uk/rss/on_this_day/front_page/rss091.xml) Do other news channels etc do similar?

That works great thanks alot.
Title: Re: "Today in History" block
Post by: bloc on November 05, 2005, 07:26:02 PM
Yes, works fine it seem. Thanks for the link, nokonium.
Title: Re: "Today in History" block
Post by: Nokonium on November 05, 2005, 08:41:00 PM
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.nokonium.plus.com%2Fblack-cat%2Fgreetings%2FWoot.gif&hash=939aad5561914e0b24f8df13e763e73e914e81b0) (https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.nokonium.plus.com%2Fblack-cat%2Fgreetings%2FWoot.gif&hash=939aad5561914e0b24f8df13e763e73e914e81b0) (https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.nokonium.plus.com%2Fblack-cat%2Fgreetings%2FWoot.gif&hash=939aad5561914e0b24f8df13e763e73e914e81b0)

Doesn't it just  ;D

Title: Re: "Today in History" block
Post by: iowamf on November 05, 2005, 09:45:02 PM
Looks great ... here's another good looking RSS block.  8)

http://www.tinyportal.net/smf/index.php?type=rss;action=.xml;

If there was a way to pull in a site's own RSS from a specific board only and make it look this good - that would be awesome ... I think this box looks better than the "Recent Topics" SSI box.
Title: Re: "Today in History" block
Post by: bloc on November 06, 2005, 04:08:55 PM
yeah, it did in fact.. :)

I will look into it. The xml option of SMF is a part all to itself, not "outside" like SSI.php is. But it should be possible to make "recent topics/posts" act like this. :) Then let the ssi function just do what it already does. As of now, TP's "recent topics" block and the ssi-type block do the same thing really..just slightly different presented.
Title: Re: "Today in History" block
Post by: crip on November 07, 2005, 11:26:23 PM
I found this on the History Channel...This Day in History.

Updated each day.. Here (http://www.historychannel.com/tdih/tdih.jsp?category=leadstory)

crip~
Title: Re: "Today in History" block
Post by: domp on November 12, 2005, 08:20:09 AM
Should this work with 1.0.5 too ?
Title: Re: "Today in History" block
Post by: IchBin on November 12, 2005, 10:18:13 PM
Shouldn't matter with SMF version. TP is what handles it.
Title: Re: "Today in History" block
Post by: crip on November 13, 2005, 12:32:08 AM
Yeepeee,  ;D ;D
I finally got this to work by unzipping the file first, couldn't run it zipped, kept getting Syntax errors? She's goin now though..does this change each day?.. weekly..monthly..et-ceteras??

Thanks,
crip~
Title: Re: "Today in History" block
Post by: bloc on November 13, 2005, 09:11:38 AM
Each day I assume.. ;) "today in history"...
Title: Re: "Today in History" block
Post by: crip on November 13, 2005, 01:33:45 PM
Exactly.. I'm a bit  :uglystupid2: .. it does change daily..

thanks -  ;)
Title: Re: "Today in History" block
Post by: JayT on January 29, 2006, 07:04:25 PM
Love this.

Couple of questions and maybe errors. Mine just looks like a big log of information. The dates are not separated nor in bold font.

Also, is there a way to change the font size?
Title: Re: "Today in History" block
Post by: Mitch on February 18, 2006, 07:56:04 PM
Thanks Bloc worked like a charm I am a big fan of history so I will enjoy this!
Title: Re: "Today in History" block
Post by: nikita on August 19, 2006, 05:47:50 PM
Nice block - this one.... i just started using it on one of my new site... i use the Alienation Theme.. which is real cool.. :up: but this block breaks the page.. i mean the width.. we have inserted some code similar to the height code but it gives a scrollbar on the bottom and it looks weird... am using the bbc block now with javascript... it wud be better if we could use the sql table imported....  :(

www.mediaplus.in
Title: Re: "Today in History" block
Post by: clickbouyow on August 19, 2006, 07:21:09 PM
It is probably because of punctuation in the datafile. If you scroll down you will find the sentence that is causing it.  I just went into phpmyadmin and edited that story and it was fine.
Title: Re: "Today in History" block
Post by: yjobcreations on October 02, 2006, 03:33:35 AM
Quote from: graffixjones on October 31, 2005, 06:52:47 PM
Unfortunately, no. :(

It's probably a Safari bug... the rest of the blocks work fine...

However, I was able to echo in some table settings for the block

echo '<table width="100%" border="0"><tr><td>';
//the block code//
echo '</td></tr></table>';


And now it works fine in any position... thanks for looking into it though, I appreciate it.

so now, on what line should i insert this code? it's still overlapping on my other blocks.

:)
Title: Re: "Today in History" block
Post by: greenman on January 10, 2007, 04:33:31 AM
Quote from: Bloc on October 29, 2005, 01:25:30 AM
import the sql file in the attached zip-file to your database. If you do not, it will give an database error.
Umm... what attached zip-file? ???
Title: Re: "Today in History" block
Post by: bloc on January 13, 2007, 10:36:04 PM
I am afraid the server move last year led to a number of attachments were lost. So until that zip is recovered again, I can't re-attach it.
Title: Re: "Today in History" block
Post by: greenman on January 13, 2007, 11:33:59 PM
oh. :(

well, can you upload it somewhere else and link to it please? :)
Title: Re: "Today in History" block
Post by: bloc on January 14, 2007, 04:48:18 PM
I just said I can't re-attach it. If I had it I would.
Title: Re: "Today in History" block
Post by: clickbouyow on January 14, 2007, 06:07:51 PM
Here ya go:

http://www.deadboneplatoon.com/misc/nuke_ephem.zip
Title: Re: "Today in History" block
Post by: bloc on January 14, 2007, 10:28:20 PM
thanks, clickbouyow. :)

I attached to first post as well.
Title: Re: "Today in History" block
Post by: greenman on January 15, 2007, 11:16:28 PM
thanks. :)


I'm using this code outside of my SMF, in a custom php page, and I get the "No database selected" error.
How can I "select the database"?
sorry for my newbiness.
Do I need to have a password to select the db? Because I already forgot the user password.. :(
Title: Re: "Today in History" block
Post by: clickbouyow on January 16, 2007, 01:11:00 AM
Read the first post.  You have to import the sql into your database.
Title: Re: "Today in History" block
Post by: greenman on January 16, 2007, 01:13:43 AM
...I know. I did. :-\

Like I said, I'm using the code outside of SMF & TinyPortal, so that's probably why I get the error.
Title: Re: "Today in History" block
Post by: bloc on January 16, 2007, 06:54:41 PM
Yes, that will cause trouble. You need then to supply host, user and pass for the sql server. SMF/TP already does that for you.
Title: Re: "Today in History" block
Post by: greenman on January 17, 2007, 01:57:18 AM
Ok.
Well I forgot my password for the user of the db, anyway to recover it?
In SMF I see the password but in * characters.
Title: Re: "Today in History" block
Post by: bloc on January 17, 2007, 09:03:44 AM
If you use the same db as your forum for this, check Settings.php in the forum folder. Its all there. Chances are you even use the same SQL user for other db's as well. :)
Title: Re: "Today in History" block
Post by: greenman on February 03, 2007, 02:32:56 AM
Got it working, thanks Bloc! :)


One other thing though, to me it shows the paragraph as 1 big sentence, no br's.
In the database it is just broken up in paragraphs without any html.


What I'm talking about:
(February 2nd, Today in History)

Text format in database:
Quote1942 Quisling becomes prime minister of puppet regime in Norway

On this day, Vidkun Quisling, a collaborator with the German occupiers of Norway, is established as prime minister of a puppet government.

On April 9, 1940, German warships entered major Norwegian ports, from Narvik to Oslo, deployed thousands of German troops, and occupied Norway. German forces were able to slip through the mines Britain had laid around Norwegian ports because local garrisons were ordered to allow the Germans to land unopposed. The order came from a Norwegian commander, Vidkun Quisling, who was loyal to Norway's pro-fascist former foreign minister.

Hours after the invasion, the German minister in Oslo demanded Norway's surrender. The Norwegian government refused, and the Germans responded with a parachute invasion. In September 1940, "commissarial counselors" in the control of the Germans replaced Norway's administrative council. Chief of these "counselors" was Quisling, who was given dictatorial powers and who proceeded to earn the enmity of Norwegians as he sent thousands of people to German concentration camps and executed members of the resistance movement.

On February 1, 1942, the commissarial counselors formed a formal government loyal to Germany, with Quisling as its prime minister. When Germany finally surrendered in May 1945, Quisling was arrested by Norway's Allied liberators, tried for treason, and executed. His name continues to be a synonym for "traitor."


Displayed on webpage:
Quote1942 - 1942 Quisling becomes prime minister of puppet regime in Norway On this day, Vidkun Quisling, a collaborator with the German occupiers of Norway, is established as prime minister of a puppet government. On April 9, 1940, German warships entered major Norwegian ports, from Narvik to Oslo, deployed thousands of German troops, and occupied Norway. German forces were able to slip through the mines Britain had laid around Norwegian ports because local garrisons were ordered to allow the Germans to land unopposed. The order came from a Norwegian commander, Vidkun Quisling, who was loyal to Norway's pro-fascist former foreign minister. Hours after the invasion, the German minister in Oslo demanded Norway's surrender. The Norwegian government refused, and the Germans responded with a parachute invasion. In September 1940, "commissarial counselors" in the control of the Germans replaced Norway's administrative council. Chief of these "counselors" was Quisling, who was given dictatorial powers and who proceeded to earn the enmity of Norwegians as he sent thousands of people to German concentration camps and executed members of the resistance movement. On February 1, 1942, the commissarial counselors formed a formal government loyal to Germany, with Quisling as its prime minister. When Germany finally surrendered in May 1945, Quisling was arrested by Norway's Allied liberators, tried for treason, and executed. His name continues to be a synonym for "traitor."

Anyway to fix that besides having to put br's in every single "pn_content" ?
Title: TIME ZONE PROBLEM
Post by: qayyom on March 03, 2008, 05:36:53 AM
there is a problem with time zone detection.

my local time zone have +11 difference from my HOST Server.

is it possible that this function detect Local time zone ?

Because now 10:35AM / 03-03-2008 as Pakistan's Slandered Time, my history Block is still showing yesterdays events.

Please do something for me.
Title: Re: "Today in History" block
Post by: IchBin on March 03, 2008, 06:34:26 PM
Have you set your time preference in your profile?
Title: Re: "Today in History" block
Post by: qayyom on March 04, 2008, 01:11:33 PM
yes i set the time zone and it is as per local (Pakistan's Standard) Time zone.

mean Forum Default and my Own (User Profile) is same.
Title: Re: "Today in History" block
Post by: IchBin on March 04, 2008, 03:32:59 PM
I have no idea. Maybe it has something to do with the server time as well.
Title: Re: "Today in History" block
Post by: adirisman on May 07, 2009, 08:02:39 AM
I have the same problem.

Is there any way to fix this?
Title: Re: "Today in History" block
Post by: JPDeni on May 07, 2009, 01:50:37 PM
Add a temporary line to figure out how much the time is off from what you want. After


$today = mktime();


add


echo 'The time is now ' . date('G:i on j M Y') . '<br />';


Save the block and then go look at it. It should give you a time and date. Figure out the difference between the time displayed and the time you want, in hours. Decide whether you want to add or subtract time. (If you want the time to be later, add. If you want it to be earlier, subtract).

Now go back to your code and delete the line you just added. Change the line


$today = mktime();


to


$alter = 3; // the number of hours you want to adjust the time by. If you want an earlier time, use a negative number
$today = mktime() + (3600 * $alter);
Title: Re: "Today in History" block
Post by: adirisman on May 07, 2009, 01:58:26 PM
Thank you, JPDeni.

That works perfectly.

Title: Re: "Today in History" block
Post by: whitesox on May 13, 2009, 09:22:26 PM
hmm i miss "total posts today" can anyone write 4 me or add 2 this ??
Title: Re: "Today in History" block
Post by: Ken. on May 13, 2009, 09:24:50 PM
Quote from: whitesox on May 13, 2009, 09:22:26 PM
hmm i miss "total posts today" can anyone write 4 me or add 2 this ??
Whitesox, please don't cross post, or double post.
I've already answered you in your other topic and hopefully one of our code specialists will take a look at your request later today or tomorrow.
Title: Re: "Today in History" block
Post by: whitesox on May 13, 2009, 10:12:24 PM
sry  ??? ::)