hi

I know I am missing a lot in my knowledge, but I'm trying to figure
something out & seemingly am in a hole...

the task is as follows:

1) query a mysql database for as many records as match a criteria
        (I can do this OK)

2) put the resulting records, how ever many there are, into a list or an
array

3) count the number of records I have retrived
        (I can do this OK)

4) choose a random record number
        (I can do this)

5) get the record corresponding to the random record number from the array

6) get a particular field from the stored record

I am using DBI to get the data from the database. here is what I have so
far:

sub getRandomRecord{
  my $cgi = shift;
  my $dbh = shift;
  my $month = shift;
  my $day = shift;

  my $searchResult;
  my $returnValue;

   #prepare and execute SQL statement
    $sqlstatement = "SELECT * FROM $TABLE WHERE month like $month and day
like $day";
    $sth = executeSQLStatement($sqlstatement, $dbh);

   $counter = 0;

   # put the records returned in an array/list & count how many
    while ($searchResult = $sth->fetchrow_array() )
    {
    # get the 4th field from the record in the array & put it in the list
    my @list = ($searchResult[3]);
     ++$counter;
   }

    # pass the counter to the random integer routine & get a value back
    my $randomNumber = getRandomNumber($counter);

    $returnValue = @list[$randomNumber];

   # clean up the DBI
   $sth->finish();

   return $returnValue
   }




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to