How to Display a Random FAQ Record on Home Page?

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
toronto905
Posts: 5
Joined: Wed Sep 17, 2008 8:11 pm

How to Display a Random FAQ Record on Home Page?

Post by toronto905 »

On my website homepage, I have a simple PHP script , that picks a random Youtube clip from an array (Youtube IDs stored in a text file) and basically everytime a user loads the home page, he sees a different Youtube clip. It is a very cool script and people love it.

I would like to do the same thing, using the same script, to display a different random FAQ record, everytime a user loads our page. I think I can use the same script, and it should work fine.

My only problem is, I don't know how to select my FAQ records? Where would the script look for, to get all my FAQ records?

Anyway, here is the code for the Youtube script, and I would really appreciate if someone can help me figure out how to do it for PHPMyFaq.


<?php

// Build an array from the list of YouTube videos
// Replace YourVideoList.txt with the path to your text file
// This will likely be something like /home/accountname/public_html/foldername/etc
$video_array = file('YourVideoList.txt');

// Randomly pick one video from the array
$video = $video_array[rand(0, count($video_array) - 1)];
$video = trim($video);

?>

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/<?php echo $video;? >"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/<?php echo $video;?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>



Thanks a lot
Nonnus
Posts: 19
Joined: Thu Oct 09, 2008 2:46 pm
Location: Portugal

Post by Nonnus »

I think the table faqdata contains all the faq records.
Lidio
Posts: 25
Joined: Mon Dec 10, 2007 9:26 pm

Post by Lidio »

Hi Toronto905 (I know where that is ;) )

you can display a ticket by using the "solution id" method. So have the URL look like: http://your site here/index.php?solution_id=NNNN where the NNNN is the article id. If you haven't deleted any articles than they would be sequentially from (most likely) 1000 and generate the number randomly.

Note, is you are using mod_rewrite the URL will look like http://your site here/solution_id_NNNN.html

Good luck,

Lidio.
Post Reply