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,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,911
  • Total Topics: 21,307
  • Online today: 871
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 885
  • Total: 885

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

#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.

This website is proudly hosted on Crocweb Cloud Website Hosting.