[FX.php List] Random Image
DC
dan.cynosure at dbmscan.com
Thu Jan 18 08:37:10 MST 2007
forget calculating a number and then parsing the array.
just use PHP's array_rand() to get a record key and use that.
this code is tested.
<?php
// mock up array like FX.php data
$searchResult['data'] = array(
'1.1' => array('fieldname' => array('data1')),
'2.2' => array('fieldname' => array('data2')),
'3.3' => array('fieldname' => array('data3')) );
echo '<pre>';
print_r(($searchResult['data']));
$rand_key = array_rand($searchResult['data']);
//print_r($rand_key);
print_r('RANDOM value from fieldname:');
print_r($searchResult['data'][$rand_key]['fieldname'][0]);
echo '</pre>';
?>
cheers,
dan
Roger Price had written:
> I need to be able to select a random field value from found set!
>
> Using 'FMFindAny' overrides any other search criteria and select a value
> from anywhere in tha database.
>
> I have tried a standard 'FMFind' with the appropriate search parameters
> and get the 'Found Set' that I wish to select from.
>
> Using:
> $n = rand(0,$imageData['foundCount']-1)' should give an integer within
> the range of the 'Found Count' (beginning at zero).
>
> But how do I display the $nth instance of the field 'image_name'?
>
> Please can anyone advise me
>
> Roger
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list