Forum Moderators: coopster
I would like to do the same thing, using the same script, to display a different random FAQ record (using PHOmyFaq), 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
sample:
<?
function getRandomFaq(){
$sql = "SELECT * FROM FAQ_TABLE ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql);
$content = mysql_fetch_assoc($result);
return $content;
}
?>
Just wondering, when you select from the table, are you selecting from a specific table? in other words, I have to know what the table is called, where the FAQ records are stored, and replace it in
"$sql = "SELECT * FROM FAQ_TABLE ORDER BY RAND() LIMIT 1"; correct?
As for PHPmyFaq forum, yes I already asked there, but no reply yet.
The only problem now is, the display, which I would like to tweak a bit to show the following:
-The record name: The field name in sql is 'thema'
-The first 10-15 words of the record, and then to read more, people have to click on a link. Field name in sql is 'content'
Like this for example:
Yahoo: An online search engine, as well as a portal, offering....(click to read more)
How can I accomplish the above please? I will be so happy if I can finally achieve this.
And here is the code I am using for this script
// Create the connection and select the DB
$link = mysql_connect("host","user","password");
if ($link) {
mysql_selectdb("phpmyfaq_database",$link);
// Select records from the DB
$query = "SELECT content FROM pmf_faqdata ORDER BY Rand() LIMIT 1";
$result = mysql_query($query);
// Display records from the table
echo "<table border='1'>";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[1]</td></tr>";
}
echo "</table>";
} else {
echo "Can't connect to the database!";
}
Thanks a lot guys,
Oh, and one thing to help you debug your code; where you have the "can't connect to database" or other such error message, add a three digit number (that you randomly make up and type in) to that error message so that you can find where in the source code your failure occurred.