Randomize List But only Show One Record

7 posts by 4 authors in: Forums > CMS Builder
Last Post: May 14, 2012   (RSS)

Re: [justritedesign] Randomize List But only Show One Record

By (Deleted User) - April 17, 2012

Hi Michael,

If you're loading all the records from the table, you can randomly select a record from the array with array_rand:
$rand_key = array_rand($did_you_knowRecords, 1);

and then output the specific record like this:
<?php echo $did_you_knowRecords [$rand_key]['title'] ?><br/>
<?php echo $did_you_knowRecords [$rand_key]['content'] ?>


Let me know if this helps.

Tom

Re: [Tom P] Randomize List But only Show One Record

By Mohaukla - April 17, 2012

Ahhh yes OK that works great.

Thanks Tom
Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

Re: [justritedesign] Randomize List But only Show One Record

By Rohwer - May 11, 2012 - edited: May 11, 2012

I got my result to show perfectly but how do I pull in the image in the $upload table that ties to the random record I am pulling in my main table ($newvehicles) ???

Re: [Rohwer] Randomize List But only Show One Record

By Rohwer - May 11, 2012

Will be back to work on Monday to revisit this. Any help would be appreciated.

Re: [Rohwer] Randomize List But only Show One Record

By Jason - May 14, 2012

Hi,

Using the techinque above, you should be able to extract a single record.

for example:

$randomRecord = $myRecords[$rand_key];


Providing you get $myRecords as the result of a getRecords() call, you should then be able to access your upload field normally.

For example:

<?php foreach ($randomRecord['uploadField'] as $upload): ?>
...
<?php endforeach ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Randomize List But only Show One Record

By Rohwer - May 14, 2012 - edited: May 14, 2012

Jason and Tom,

Thank you one more time. Support here is amazing and it is very appreciated.

- Rohwer