Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 8095 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hello, this is my question:

i have one db with different record of two tipes: field1 can be A or B.

I need to perform a find that:

- display only the records with filed1 = A

- from the records with field1 = A it gets one in random mode

This is what i've tried and what i've discovered:

1. Findany doesn't perform a preliminary search but publish a random record (i have put a correct search link but findany find a random record despite of fields search)

2. I've set up a script named "random" wich make the db goes to the next record at every search in order to rotate the publishing with Find. Tried also with FindAll. But the web page publish only the first record even if the db goes to the next.

Any suggestion?

Thanks

Posted

First off you have not said whether you are trying to achieve your publishing goals with Instant or Custom Web Publishing (but I get the feeling it is IWP).

Second, if you are using CWP, you really need to have the cdml reference database, available free from FMI.

Third, there are issues with running ScriptMaker in a browser solution. You can search these forums for such discussions. You can also visit my site for cautions about using ScriptMaker.

Posted

You're right i didn't say i 'm publishing with Custom Web publishing.

I'll take a look to your site.

I don't need to run scriptmaker, it was only a test to find a solution.

Any idea?

Posted

Look at the -Skip tag to force FileMaker to return a record other than the very first one. If you can somehow populate this with a random number (using Javascript, I guess), you could get FileMaker to return a random record in which Field1 = A. Your link would look something like this:

FMPro?-DB=database.fp5&-Lay=layout&-Format=format.html&-Error=error.html&-Max=1&-Skip={random number here}&Field1=A&-Find

The danger here, of course, is that the random number generated could be more than the actual number of records in the database, so watch out for that.

Hope this helps.

Posted

Great, i new there was a cdml that could help me but i couldn't remeber what... it was skip!!!!!!

Thanks a lot.

These are the news:

- Everything goes great with skip (if skip is major than the number of records i think it publish the last one)

And now....any suggestions? I'll try something i have in mind if you get an idea please write it.

Thanks

Posted

This is untested and off the top of my head:

<body>

<script>

var i = Math.round(Math.random() * 100)

document.write("<a href="FMPro?-DB=database.fp5&-Lay=layout&-Format=format.html&-Error=error.html&-Max=1&-Skip=" + i + "&Field1=A&-Find">Click Here to Go to Random Record<//a>")

</script>

</body>

Posted

It works. Thanks again

One more question:

this is what i have set up:

the index page of my site is composed by two frame

the frame 2 (the main one where people navigate) perform the redirect to the search of fmp automatically...i need to put that javascript to that frame in order to perform the random search.

Is it possible without going to another page again (where i put the redirect again) or i need to redirect two times the visitors?

Thanks

Posted

Hi David,

Sorry for the late reply -- I'm glad my script worked for you.

To get your frameset to automatically load a random page into one of your frames, try this:

<html>

<head>

<script>

function GetRandomRecord() {

var i = Math.round(Math.random() * 100)

return "http://FMPro?-DB=database.fp5&-Lay=layout&-Format=format.html&-Error=error.html&-Max=1&-Skip=" + i + "&Field1=A&-Find"

}

</script>

</head>

<frameset>

<frame name="MenuFrame" src="menu.html">

<frame name="MainFrame" src="javascript:'parent.GetRandomRecord()'">

</frameset>

</html>

I haven't tested this, so let me know how it works out.

Posted

Hello, thanks for your time, but i doesn't work.

The only thing i see is the name of the function in the frame. It seems to me it doesn't run the javascript.

Posted

Hmm. You might want to replace the first <script> tag with <script language="JavaScript">

Failing that, here's a slightly different approach:

<html>

<head>

<script language="JavaScript">

function GetRandomRecord() {

var i = Math.round(Math.random() * 100)

parent.MainFrame.location ="http://FMPro?-DB=database.fp5&-Lay=layout&-Format=format.html&-Error=error.html&-Max=1&-Skip=" + i + "&Field1=A&-Find"

}

</script>

</head>

<frameset onLoad="GetRandomRecord()">

<frame name="MenuFrame" src="menu.html">

<frame name="MainFrame" src="blank.html">

</frameset>

</html>

Where blank.html is an empty HTML page. Again, I haven't tested this, and this is pushing the limits of my JavaScript ability; if someone else here sees any obvious problems (or better, solutions), feel free to jump in at any time! smile.gif

Posted

You could try this for testing:

<script language="JavaScript">

function GetRandomRecord() {

var i = Math.round(Math.random() * 100) ;

alert ("The number is " + i) ;

parent.MainFrame.location ="http://FMPro?-DB=database.fp5&-Lay=layout&-Format=format.html&-Error=error.html&-Max=1&-Skip=" + i + "&Field1=A&-Find" ;

}

</script>


All the best.

Garry

Posted

Ok these are the news:

I've set up a correct configuration of javascript and it works:

<html>

<head>

<script language="JavaScript">

function GetRandomRecord() {

var i = Math.round(Math.random() * 100)

parent.main.location= "http://FMPro?-DB=database.fp5&-Lay=layout&-Format=index1.html&-Error=error.html&-Skip=" + i + "&field1=a&-Find"

}

</script>

</head>

<frameset rows="0,*" border="0" framespacing="0" frameborder="no">

<frame src="testa.html" name="testa" noresize>

<frame src="javascript:parent.GetRandomRecord()" name="main" noresize>

</frameset>

</html>

The error was in the-- frame src="javascript:parent.GetRandomRecord()"-- that must be without the '.

THANKS TO ALL for your help.

Note: on a win browser everything is ok. On mac browser (same as win) i'm finding problems whith links to this page (the one of the code above) Sometimes the page, after the click on the link, is blank so when i refresh it's ok... any ideas?

Have a nice week end.

David

Posted

Excellent! I'm glad to hear that my meagre (but growing) JavaScript skills have helped you out. And thanks again for identifying the problematic syntax. I've made a note of it.

As for the link problem, try implementing it in a non-framed page and look at the address that appears. Is i populated with a value? If i is greater than the number of records, does the link work?

Now that I think about it, the Math.random() function returns a number between 0 and 1... perhaps this will help:

var i = Math.round(Math.random() * 100) + 1

...that is, if the problem lies in -Skip=0.

Hope this helps!

Posted

hello,

i've inserted the new math function you suggested. But i think the problem isn't there.

This is the eviroment where i find the error:

After going to the main page with the javascript i navigate into the next page, i've set up a link at the bottom to go to the main page. With IE 5.1 for mac os 9 i click the link to go to the main page and it seems to me that the javascript doesn't run. I have a blank page as result. So when i write the domain name again it works.

Very strange.

The link to go to the main page is something like: http://ipadress/index.html where index.html is the page I set up with your script.

This problem doesn't occur on win machines. Could it be a problem with IE 5.1 on mac?

Thanks

Posted

After a lot of tests i've found out that the error was simply in the type of link.

I needed to put a full link and not a relative path.

Now all is ok.

I want to thank all who helped me in the solution of my problem, and i hope that this post will be of help for future visitors who have the same problem.

Have a nice day to all.

David

This topic is 8095 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.