You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 339 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
How to enter thousands of ephemerids

27.8. How to enter thousands of ephemerids

Figure 27-7. Administration panel: Ephemerids.

Administration panel: Ephemerids.



Problem: You have a file of nice quotes (often called "fortunes") that you would like to see displayed every day in the Ephemerids module (see Section 6.1 for the user view and Section 7.1 for the administrator view of the Ephemerids module) . You don't want to write all those texts by hand, so you are looking for a way to automate the text insertion.

Idea:The right command to insert a text in the Ephemerids table nuke_ephem is:

insert into nuke_ephem values (4,4,11,2002,
"Nothing cures insomnia like the realization that it's time to get up.",");

We will use a script to produce these INSERT commands (see Inserting Ephemerids through script).

Solution: We write a script like:

#! /bin/sh
did=6
while [ $did -le 30 ]; do
  read LINE
  if [ -n "$LINE" ]; then
    echo "insert into nuke_ephem values (",$did,11,2002,\"$LINE\",");"
    did=$((did+1))
  fi
done

Let's call it "ephemerids" - don't forget to make it executable. When executed, the ephemerids script outputs the MySQL INSERT command we saw above, for each fortune in the standard input. Suppose that the "fortunes" are in the file called "myfortune", one fortune per line. Then, if you use the script as follows:

ephemerids < myfortune > ephemerids.sql

it will create the necessary MySQL statements and put them all in the ephemerids.sql file. Once ephemerids.sql is created, you only need to import it in the PHP-Nuke database. For this, you can type

mysql -u dbuname -h dbhost -p dbname < ephemerids.sql

or use the import function of phpMyAdmin (Section 3.3).

Verification: To show the content of nuke_ephem and verify that the fortunes were inserted, execute the following SQL query:

select eid,did,mid,yid from nuke_ephem;

Note that in this version, the above problem can be easily solved with the Random Quotes block (see Section 8.2.8). However, instead of fortunes, you could just as well have the birthdays of hundreds of people, or the dates and descriptions of thousands of historical events, as in a classic ephemerids context.

Powered by TOGETHER TEAM srl ITALY http://www.togetherteam.it - DONDELEO E-COMMERCE http://www.DonDeLeo.com - TUTTISU E-COMMERCE http://www.tuttisu.it
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.127 Seconds - 197 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::