TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,982
  • Total Topics: 21,320
  • Online today: 1,186
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

Custom php

Started by handoyo, December 08, 2009, 03:44:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

handoyo

Hi all,i'm new to tiny portal..I'm wondering suppose for eample i want to display random words of the day on the left block.What should i do?I know a little php mysql..Where can i start?Thanks a lot guys...

Lesmond

Welcome to Tinyportal handoyo

You could search for "Random Word Generator"

handoyo

Is it on http://www.tinyportal.net/index.php?topic=23876.msg192556#msg192556 ? Should i just paste the code on the php block?Thanks Lesmond

Lesmond

yeah thats the one, php block is correct, there is about 3 versions in that topic :)

handoyo

Ok,by the way,what if i'm intending to use database to hold the data an get the words from it?Are there any tutorial about it with tp/smf?Thanks...

Lesmond

Will have to wait for someone else to answer that one, me and databases dont get on   :o :tickedoff:

handoyo

Ok,thanks Lesmond.God Bless You..  ;D

JPDeni

You'd have to give more information about how you want your database set up to be. But it would be easier to just keep it in the code if you're just putting out a random word.

If you want to keep the same word for every person for a whole day, that's a whole different concept than displaying a random word. So I need you to fully explain what you want to do before I write any new code.

handoyo

Hi JPDeni,actually i'm intending to put random bible verse.. The database structre should be like i.e.

id     name       verse                                          text
1     matthew   6:10    Thy kingdom come, Thy will be done in earth, as it is in heaven.

It will be shown once in a day and shown for every person....On the next day,it will be radomized again..Thanks...



JPDeni

Okay. I think I can do that. It would be easier if you just set which verse would be the verse of the day or if it was a new random one every time the page is reloaded, but I can probably find a place to store what the random verse is for the day. I'll take a look at where the best place would be to store it.

handoyo

#10
Thanks a lot JPDeni...May God bless you for your kindness  :D

Lesmond

wait, dosnt Crip do something like this on his site, bit late here in the UK erm 3.40 am

Lesmond

handoyo try a search for "bible" here on tp

handoyo


handoyo

HI Lesmond,i've serach it here,if i'm not wrong,Crip create the bible search i suppose.Not random verse..Thanks...

JPDeni

In case you still need it....

You need to set up your verses table just the way you described it earlier and name it verses. Be sure that your field names are the same as you indicated before, with the same lack of capitalization -- id, name, verse, text -- because that's how I've created the code.

Use this in a php block or php article:


global $db_prefix, $modSettings;

if ((date('z',$modSettings['verseDate']) <> date('z',time())) OR !isset($modSettings['verseDate'])) {
$result = db_query("
SELECT *
FROM verses
ORDER BY RAND()
LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
$modSettings['verseDisplay'] = '<b>' . $row['text'] . '</b> ' . ucfirst($row['name']) . ' ' . $row['verse'];
mysql_free_result($result);
$date = time();
$verse = $modSettings['verseDisplay'];
db_query("REPLACE INTO {$db_prefix}settings (variable, value)
VALUES ('verseDate','$date')", __FILE__, __LINE__);
db_query("REPLACE INTO {$db_prefix}settings (variable, value)
VALUES ('verseDisplay','$verse')", __FILE__, __LINE__);
}
echo $modSettings['verseDisplay'];


If you want the format any different, I can alter it for you, but I'll need to know what you want.

handoyo

Thanks JPDeni,but before that,how should i handle the database?Should i just enough by creating the verses table?Thanks..

JPDeni

Quote
Should i just enough by creating the verses table?

I'm not sure I understand what you mean. I thought you had already done that. Isn't the database table already made?

handoyo

Not yet..Suppose i got the database table made,all i have to do is put the code that you gave me on the php block,don't i?And i don't have to modify or create a new php file to open the database connection,isn't it?Thanks...

JPDeni

QuoteSuppose i got the database table made,all i have to do is put the code that you gave me on the php block,don't i?

Yes. Assuming that the table is called verses and the fields are set up like you said they will be -- and you put the table into the same database where the SMF and TP tables are -- you will just need to put the code into a php block and it should read the table just fine. I made a table (with just two verses in it) to test it out and it worked great.

handoyo

Great,thanks a lot JPDeni.. :D

handoyo

I've tested it JPDeni...It works the way i want,by the way.What if i'm trying to use time instead of date.For example after 6 hours,the verse will change to another..Thanks..

JPDeni

If someone else wants to work on that, fine. But it's way too much work for me to do.

handoyo

Ok,thanks a lot by the way for the code that you gave to me.God bless you.. :)

This website is proudly hosted on Crocweb Cloud Website Hosting.