Gossamer Forum
Home : Products : DBMan : Customization :

"Question of the Day" Display

Quote Reply
"Question of the Day" Display
How can we display a different record each day based on date?

Here's our situation:

We have just begun working with a new online training company and have proposed the we include on our home page a link to a "Question of the Day" We set it up so the link opens a small pop-up window that will show a question of the day, the multiple choice selections, and a "click here" for answer link. This link will then go to the sponsors web site to display the answer. It's a pretty interesting advertising format and will provide valuable education to our readers.

The sponsor uses CFM to create their site and scripting requirements for their QoD set up. They sent us the database which contains three fields:

Date|QoD w/Choices|Answer Record Number

Here's an example:

07-Jun-00|"<b>To care for a patient with a suspected pelvic fracture, you should</b>

A. apply the PASG, start two IVs, and monitor for signs of shock

B. immobilize the patient to a spine board and transport immediately

C. align the lower limbs, apply splints, and administer analgesics

D. do not immobilize; monitor distal pulse and sensation and transport immediately
"|386

Please take a look at a sample page we created statically with just one of the questions:

http://www.merginet.com/index-lx.htm

Click the link for QoD near the top left of our logo. Do a view source and you will see the link to their site for the answer is: http://www.learnx.com/ems/answer.cfm?DQ_id=372. That will show you where the record number needs to be inserted.

I think it's pretty easy to set this up using DBMan but how can we get this to use the date field to post the question of the day with each day's question being different?

I look forward to any ideas.



Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com
Quote Reply
Re: "Question of the Day" Display In reply to
Setting up the database wouldn't be too hard. Can you take care of the popup window?

My only real concern is that the choices seem to be in the same field as the question. How are the choices indicated within the database?

JPD
Quote Reply
Re: "Question of the Day" Display In reply to
Carol,

Pop-up window is the easy part. I already have it working in the sample but could probably also set it up through the script in html.pl if necessary.

I separated the question from the choices, added an ID number for DBMan and a User ID for posterity :-)

Here's what it looks like now:

1|07-Jun-00|<b>To care for a patient with a suspected pelvic fracture, you should</b>|A. apply the PASG, start two IVs, and monitor for signs of shock
B. immobilize the patient to a spine board and transport immediately
C. align the lower limbs, apply splints, and administer analgesics
D. do not immobilize; monitor distal pulse and sensation and transport immediately
|386|Richard

OK, any suggestions? Also, I use html.pl with short/long/user-friendly with additions of What's New, File Upload etc., etc. I know I don't need all that for this little function but it was in my master set up.

I look forward to your suggestions.

Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com
Quote Reply
Re: "Question of the Day" Display In reply to
If you got the popup, we got it made in the shade! Cool

On your static .html page, you would set up your link like --

.../db.cgi?db=qod&uid=default&qod=1

Set up a qod.cfg file with all of your fields. You know, you could do without the ID field. Since you have one question per day, you could use the date field as the $db_key field. It would make your .db file a little smaller and, more importantly, you could then use &get_record to pull up the record. It's faster than using the query subroutine and it requires less coding.

If you went with this idea, your fields would be
Date
Question
Answers
DQ_id
Userid

I notice that you have linefeeds in your record. You need to replace those with `` and have each record all on one line.

Once you get your .cfg file created and your .db file straightened out, you would add the following to sub main, around where the other elsif statements are:

elsif ($in{'qod'}) { &html_qod; }

(There's no need to check to see if the user has "view" permission for this.)

Assuming you have set up your fields as I outlined them above, you would add a subroutine to html.pl:

Code:

sub html_qod {

%rec=&get_record(&get_date(time));
$rec{'Answers'} =~ s/\n/<BR>/g;

print qq|the display of the record in your popup window,
using the $rec{'FieldName'} variables
include the following link

<a href="http://www.learnx.com/ems/answer.cfm?DQ_id=$rec{DQ_id}">Get Answer</a>|;

}
If you really wanted to keep the ID field, then you would use

Code:

sub html_qod {

$in{'Date'} = &get_date(time);
my ($status, @hits) = &query("view");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
%rec = &array_to_hash(0, @hits);
$rec{'Answers'} =~ s/\n/<BR>/g;

print qq|the display of the record in your popup window,
using the $rec{'FieldName'} variables
include the following link:

<a href="http://www.learnx.com/ems/answer.cfm?DQ_id=$rec{DQ_id}">Get Answer</a>|;
}
Since the dates only use two digits for the year (which I think is bad form Smile), you'll also need to change sub get_date. After $year = $year + 1900; add

$year = substr($year,2,2);


Hmmm. This may conflict with the "What's New" mod. If you're using db.cgi for other databases that have a four-digit year, we'll have to work something else out.

JPD
Quote Reply
Re: "Question of the Day" Display In reply to
I'll change the .cfg file as you suggested. The .db file doesn't have line breaks, it has BR tags which this Support Forum converted in my post. I am assuming that I can have html tags in my entries???

I use each script in its own directory and have always left everything as default. I know that's probably not good form but I never took the time to learn how to drive multiple databases from one db.cgi. I know I can change the name of the db and cfg files but I never could figure out the changes to the html.pl since each database would need different fields for different purposes.

So for your first instruction

(.../db.cgi?db=qod&uid=default&qod=1)

I will use:

.../db.cgi?db=default&uid=default&qod=1

I will set up my default.cfg file as you suggest and remove the ID field in place of the Date. I will set everything else up as you direct.

Can I just change the date in the db file from

07-Jun-00

to

07-Jun-2000

I can do that globally since right now there are only 65 questions. If that will work, then I'll set it up that way.

Comments?


Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com
Quote Reply
Re: "Question of the Day" Display In reply to
In Reply To:
The .db file doesn't have line breaks, it has BR tags which this Support Forum converted in my post. I am assuming that I can have html tags in my entries???
I see. Yes, you can have html tags. No problem. This means you don't need the line

$rec{'Answers'} =~ s/\n/<BR>/g;

In Reply To:
Can I just change the date in the db file from

07-Jun-00

to

07-Jun-2000
Yep.

In Reply To:
I never could figure out the changes to the html.pl since each database would need different fields for different purposes.
You would need to have separate html.pl files for each database, each with a unique name.

JPD
Quote Reply
Re: "Question of the Day" Display In reply to
>>On your static .html page, you would set up your link like --

.../db.cgi?db=qod&uid=default&qod=1

I don't think I understand this part of the link.

I am using shtml with server side includes for this pop-up page. I tried to use

!--#exec cgi="qod/db.cgi?db=default&uid=default&qod=1"--

(obviously with the tag brackets in place)

qod is the main directory with this version of DBMan in it but that doesn't work.

Any suggestions?

Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com
Quote Reply
Re: "Question of the Day" Display In reply to
!--#exec cgi="qod/db.cgi?db=default&uid=default&qod=1"--

I have no experience whatsoever with SSI, but I think you need to put the whole path in there. At least you need to include the cgi-bin part, don't you?

JPD
Quote Reply
Re: "Question of the Day" Display In reply to
OK, I removed the line...

$rec{'Answers'} =~ s/\n/<BR>/g;

I changed the date format to four digit years.

The script runs fine. Now how do I get the record to insert in my static html page that uses SSI??

Thanks for your help and persistence.

Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com
Quote Reply
Re: "Question of the Day" Display In reply to
Well, I tried it withg a full URL and a partial.

!--#exec cgi="http://www.merginet.com/qod/db.cgi?db=default&uid=default&qod=1"--

Still get an error.

How did you originally view this link being set up to call the question of hte day?? That's where I am lost.

Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com
Quote Reply
Re: "Question of the Day" Display In reply to
I tried the URL and the script isn't running fine. I think we need to get it running without the SSI before you try that.

So far there are two problems. One is that your pages don't show up at all in a Netscape browser. You seem to be missing the closing </table> tags on your pages.

The other is that calling &qod=1 gives an internal server error. I'm not sure why.

I think I need to look over both your html.pl file and your db.cgi file. Do you know how to post them to the web where I can see them?


JPD
Quote Reply
Re: "Question of the Day" Display In reply to
Carol,

Good morning. I have uploaded all files as .txt files in directory http://www.merginet.com/qod/

[link]http://www.merginet.com/qod/html.pl.txt[/link]
[link]http://www.merginet.com/qod/default.db.txt[/link]
[link]http://www.merginet.com/qod/default.cfg.txt[/link]
[link]http://www.merginet.com/qod/db.cgi.txt[/link]

I set up the database and cfg as you indicated and I can get
[link]http://www.merginet.com/qod/db.cgi[/link] to open and run (use admin/admin) but no records will show because it tells me that I have an invalid date format. When I try to add a record, it dumps the next record number from default.count into the date field. Obviously I missed something here.

Also, on the pop-up window, here's how I created it.

On the static web page inside the head tag, I use a javascript function to create a pop-up window. Do a view source on [link]http://www.merginet.com/main-lx.shtml[/link]. You'll see the basic script code. Then look at the QoD link next to our logo and you'll see the call using your configuration which as you indicated is tossing us a 500 server error

a href="javascript:openWindow('qod/db.cgi?db=default&uid=default&qod=1');"

Of course this page is normally trapped in a frame so it will look poorly formatted when you dial it up direct but that's irrelevant here.

I really, really, really appreciate your help here.

I look forward to your comments. Thank you again!

Richard Bilger, Publisher
MERGInet Medical Resources
[link]http://www.MERGInet.com[/link]
Quote Reply
Re: "Question of the Day" Display In reply to
Okay. The reason no pages show up when I try to access the database using Netscape is that you have some problems in sub html_page_bottom.

It should be

Code:
print qq|
<P>
<div align="center"><$font_small color="#C0C0C0">
Brought to you by Learning Express (LearnX.com).
</font></div></td></tr></table></body></html>
|;
The problem you're having with adding records is that you have $db_key_track = 1; in your .cfg file. (My fault. I should have mentioned it.) Since you're using the Date field as your key field, you don't want the database to provide a key value. Set

$db_key_track = 0;

in your .cfg file.

Selecting "List All" is going to be problematic, because of the way DBMan deals with dates. (I wasn't thinking about that.) You can just set the field type of the Date field to 'alpha' though and it wouldn't hurt anything.

I was able to see the records by entering a * in the "Question" field -- and using MSIE. Smile

None, of this, of course, addresses the 500 error. Back to the files! Smile

I think I've got it!

I wasn't clear on creating sub html_qod.

You need to have the full html formatting within the subroutine.

Code:
sub html_qod {
# --------------------------------------------------------
# Question of the day set up.
#
%rec=&get_record(&get_date(time));
$page_title="Question of the Day";
&html_page_top;


print qq|
<$font color="#666666">
<ul><b>$rec{'Question'}</b>
<BR>
$rec{'Choices'}
</ul>
</font>
<$font color="#FF0000">For answer <a href="http://www.learnx.com/ems/answer.cfm?DQ_id=$rec{DQ_id}">click here!</a>|;

&html_page_bottom;
}
That oughta fix the 500 error. (Notice how I hedge my bet here! Wink)

You will probably want to change the formatting in the "top" and "bottom" subroutines to fit into your popup window. Most of that is going to be trial and error, though, and seeing what looks good.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: "Question of the Day" Display In reply to
It Works!, It Works!

Check it out: http://www.merginet.com/index-lx.htm
(Note: to all who read this later, this link will be removed in a day or two. IF it's not there and you want to see it work, just click to our home page.)

Thank you so much for your persistence. This will make our new partner very, very happy and should prove to be a really great addition to our site.

You're the best!



Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com
Quote Reply
Re: "Question of the Day" Display In reply to
Way cool!!! Cool

I'm really glad we were able to work it out.

(I'm sure you're still working on the page, so I probably shouldn't say anything ... but Smile the graphic to click on for the qod is squished. It took me a while to find it. Looks the "height" tag should be "80" instead of "29.")

It's such a great feeling for me to go to someone else's site and say "I did that!!" Smile

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: "Question of the Day" Display In reply to
Carol,

Thanks again. We were in the process of changing the graphic to a new version. Now it has the Star of Life behind it.

Take care and yes, tell everyone you did it. I never could have finished it without you.

Richard Bilger, Publisher
MERGInet Medical Resources
http://www.MERGInet.com