Can I have 1 or 2 random data shown on my index.html?
Aug 10, 1999, 7:36 AM
Veteran / Moderator (8669 posts)
Aug 10, 1999, 7:36 AM
Post #2 of 2
Views: 245
That's not so much of a problem as spanning random data over pages.
This is what works for me:
Have a "dummy" field in your database that doesn't have anything entered in it. You can call it anything you want and you don't need to have a field for it on a form. The only thing you need to do is set it up as a numer datatype and remember what the field number is.
In sub query, after
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);
add
srand ( );
$values[1]=int(rand(1000)) + 1;
$in{'sb'} = 1;
}
Change the 1 to the number of your dummy field.
In the beginning of html_home, add
$in{'mh'} = 1; # change this to the number you want to show
$in{'random'} = 1;
my ($status, @hits) = &query("view");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
In the place where you want to print out the records, use
for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits));
}
}
I have used this code and it works for me.
------------------
JPD
[This message has been edited by JPDeni (edited October 03, 1999).]
This is what works for me:
Have a "dummy" field in your database that doesn't have anything entered in it. You can call it anything you want and you don't need to have a field for it on a form. The only thing you need to do is set it up as a numer datatype and remember what the field number is.
In sub query, after
Code:
LINE: while (<DB> ) { (/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);
add
Code:
if ($in{'random'}) { srand ( );
$values[1]=int(rand(1000)) + 1;
$in{'sb'} = 1;
}
Change the 1 to the number of your dummy field.
In the beginning of html_home, add
Code:
$in{$db_key} = "*"; $in{'mh'} = 1; # change this to the number you want to show
$in{'random'} = 1;
my ($status, @hits) = &query("view");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
In the place where you want to print out the records, use
Code:
if ($status eq "ok") { for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits));
}
}
I have used this code and it works for me.
------------------
JPD
[This message has been edited by JPDeni (edited October 03, 1999).]

