Forum Moderators: coopster

Message Too Old, No Replies

Any idea how to get this done?

         

impact

3:26 pm on Sep 18, 2009 (gmt 0)

10+ Year Member



Hello,

I want to have a support knowledge base in my site.Does any one know how to get on with this? I have absolutely no clue about where to begin.

When my support home page loads, I want to load 5 questions from my database at random. These question will have to change every time the page reloads.

Here is what I am thinking of

index.php
----------------------------------------
<?php
include ("secure/DisplayRandomTips.php");
$displayRandomTips = new DisplayRandomTips();
$displayRandomTips->setQuestion();
$question = $displayRandomTips ->getQuestion();
$serial_number = $displayRandomTips ->getSerialnumber();

?>

<html><body>...
<a href="http://www.zipapplication.com/support/bin/answer?tag=<?php $serial_number ; ?>"><?php print $question; ?></a>
<body><html>

DisplayRandomTips.php
-------------------------------------------
class DisplayRandomTips {

var $question = "Null";
var $serial_number ="Null";

function setQuestion(){
include ("DBConnect.php");
$getData = "SELECT * FROM knowledge_base ORDER BY RANDOM()";
$getData2 = mysql_query($getData) or die("Could not query 5 column");
$getData3=mysql_fetch_array($getData2);
// Get serial_number and question from database
$this->question = $getData3['question'];
$this->serial_number = $getData3['serial_number'];
// Close mysql connection
mysql_close($con);
}
function getQuestion(){
return $this->question;
}
function getSerialnumber(){
return $this->serial_number;
}
}

I am also not sure, if this is the correct way of doing things. I was wondering is there any other better way to do this?

Thank you,

andrewsmd

4:15 pm on Sep 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could also select your min and max primary keys and then get random questions in that manner using the rand funciton. i.e. "select min(id) from table;" set $min equal to the result of that. Then do the same except replace min w/ max and then use the rand function
for($i = 0; $i < 5; $i++){
$randId = rand($min, $max);
//query
$query = "select * from table where id = '{$randId]';";

//excute the query and print results
}