Gossamer Forum
Home : Products : DBMan : Customization :

Linking database elements on static web pages

Quote Reply
Linking database elements on static web pages
Hi,

I am trying to link database elements onto static web pages that I already have on my site. For example, where i have information on a topic i want things under that item to link from my database. sort of like having a price or code for a particular item. I have tried using the "List Records by Category v1.0 (Stand Alone - SSI)" add-on from the resources page. This does exactly what I want except it lists every item in the database. What I really want is to be able to specify 1 item. Does someone know how I can do this or has a script that i could use. Please note: I have very little knowledge of perl Frown.... PLEASE HELP!!!

Thanks in advance!
Quote Reply
Re: Linking database elements on static web pages In reply to
Well, I don't "do" SSI, but you can create a link to display just one record from a static page.

Your link should look like this:

Code:
"http://url/to/db.cgi?db=default&uid=default&KeyFieldName=KeyValueOfDesiredRecord&view_records=1"

Change the db=default part if your .cfg file is not called "default."


------------------
JPD





Quote Reply
Re: Linking database elements on static web pages In reply to
Thanks for your help JPD but the only problem is that I only want 1 field to be displayed inside my static page. If I use this method it is giving me a link to go to the correct product page and lists all the fields. I just want the value of the one field to be displayed on the page. Is it possible to do this?? I tried using an <!--exec cgi="--> with the same command line you gave me but it just returns an error on my static page. Any other ideas?? Please help!

Thanks heaps,

Dave
Quote Reply
Re: Linking database elements on static web pages In reply to
So you want to display the contents of one field of one record on a static page via SSI? Will it always be the same record and the same field?


------------------
JPD





Quote Reply
Re: Linking database elements on static web pages In reply to
Yes that is correct. It will always be the same field... ie. product name but it will continually change. however manually changing this for each item is possible if really need be. thanks heaps for the help.

dave
Quote Reply
Re: Linking database elements on static web pages In reply to
I don't mean to be difficult, but wouldn't it be easier just to change the product name on the html page, rather than to pull it from the database? Or is there some reason this wouldn't work?


------------------
JPD





Quote Reply
Re: Linking database elements on static web pages In reply to
But what i am trying to do is bring in other things such as the code or price which change. so by linking them to my database the website will update as the db updates.

i am working on it now and i have sort of a work around. what i did was to use an SSI and search for my product code. then i edited the html.pl page so that the search results only returns my selected field. i know this is dodgey but i can't think of any other way to do it Frown
Quote Reply
Re: Linking database elements on static web pages In reply to
So you don't want just one field of one record. You want more than one field of the record. Right?

I just need to know what you want before I start writing code.

Is there any way to could put this static page into your html.pl file and have it displayed by DBMan?


------------------
JPD





Quote Reply
Re: Linking database elements on static web pages In reply to
ok, basically what i have is a static website on my existing website that lists different products and a short description for each. Now that stuff is fine, I don't want to get that from a database, however the item code I do. So I need something, such as an SSI that will pull that code from the database and display it on the page. so it wouldn't be possible to put this static page in the html.pl folder as it is always changing and stuff. thanks a lot for your assistance with this!

dave
Quote Reply
Re: Linking database elements on static web pages In reply to
Okay. Well, I can help with altering the script. What I can't do is tell you about calling it via SSI. (I only talk about things I have at least a little experience with and I can't use SSI on my server.)

Add

Code:
$target = the $db_key value of the record you want to find;

Delete

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "$cat_name") {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No $cat_name field defined");
}

Change

Code:
@values = split (/\Q$db_delim\E/o, $fields[$fieldnum]);
foreach $value (@values) {
if (!(grep $_ eq $value, @selectfields)) {
push (@selectfields, $value);
}
++$count{$value};
}

to

Code:
if ($fields[$db_key_pos] eq $target) {
last;
}

Change

Code:
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&$&view_records=1&ID=*&$cat_name=$sfield&sb=1&so=descend">$field</a>:</font> <$smfont>(<font color="ff0000">$count{$field}</font> )</font><BR>|;
}

to

Code:
%rec = &array_to_hash(0,$fields);

and then format your search result as you want to, using $rec{'FieldName'} variables.

Possibly someone will be able to help with how to call the script from your static page. There should even be a way for you to pass the $db_key value with your SSI call so that you don't have to edit the script every time you want to make a change.


------------------
JPD





Quote Reply
Re: Linking database elements on static web pages In reply to
so where exactly is this code that i change??
Quote Reply
Re: Linking database elements on static web pages In reply to
Sorry. I thought you were using the records.cgi script from the Resources Center. The script is here:

http://anthrotech.com/...man/mods/records.txt

------------------
JPD





Quote Reply
Re: Linking database elements on static web pages In reply to
I tried those changes but I don't think i have done it right. when i execute the cgi i get nothing displayed. And when i use some arguments the same result. i have put my records.txt file up so u can check it out if you like... its at http://www.microway.com.au/cgi-bin/records.txt
Thanks again for all this help you are a real help.
Quote Reply
Re: Linking database elements on static web pages In reply to
In some other posts, I've seen LoisC suggest using the format

<!--#include virtual="../banmat1.cgi"-->

to call the SSI script, rather than the way it is mentioned in the script itself. (I don't remember. Smile )

You might try that.


------------------
JPD





Quote Reply
Re: Linking database elements on static web pages In reply to
Ok, so just to clear things up,
with the first bit of code I want to add. if I am going to be searching for the Code would I have it as:

$target= db_key Code;

or

$target= Code;

Also for your last comment can you give me an example say if I wanted to display a field called Quantity.

Lastly, when executing this do I need to have arguments such as <!--exec cgi="../records.cgi?Code=aab"-->

Thanks.

Dave.
Quote Reply
Re: Linking database elements on static web pages In reply to
I do not know. Someone with experience using SSI will have to help you on this.

If you pass a value to the script, there will have to be some way for the script to recognize the value. I don't know if this would be the same as with a regular Perl script or not.

My understanding from previous posts on this topic is that you could use:

<!--#include virtual="../records.cgi"-->

to call the script. According what what others have written, this is preferable to using

<!--exec cgi="../records.cgi"-->

However, someone else should be better able to answer your questions.


------------------
JPD