Search Webmaster Help and Solution

RANDOM ARRANGEMENT USING ARRAY

Hello PHP Master, I need your help. I want to create a random arrangement of the options. This will be the option answers for the given question.
Below is my code, can you please check my code and help me correct it.

$selectquestions = mysql_query("select * from tblquestions where ndex = 1",$conn);
while ($dataquestion = mysql_fetch_array($selectquestions)){
$optiona = $dataquestion[fldoptiona];
$optionb = $dataquestion[fldoptionb];
$optionc = $dataquestion[fldoptionc];
$optiond = $dataquestion[fldoptiond];
}
this code is not working --> $characters = array($optiona,$optionb,$optionc,$optiond);

but if i will put directly the value like this --> $characters = array("sample option A","sample option B","sample option C","sample option D");
it works fine.


........ this part here below is working fine........
$keys = array();
while(count($keys) < 7) {
$x = mt_rand(0, count($characters)-1);
if(!in_array($x, $keys)) {
$keys[] = $x;
}
}
foreach($keys as $key){
$random_chars .= $characters[$key].<br>;
}
echo $random_chars;
...........................................................................

Guys I really need your help about this.... Thanks in advance... God Bless you all... Hello PHP Master, I need your help. I want to create a random arrangement of the options. This will be the option answers for the given question.
Below is my code, can you please check my code and help me correct it.

$selectquestions = mysql_query("select * from tblquestions where ndex = 1",$conn);
while ($dataquestion = mysql_fetch_array($selectquestions)){
$optiona = $dataquestion[fldoptiona];
$optionb = $dataquestion[fldoptionb];
$optionc = $dataquestion[fldoptionc];
$optiond = $dataquestion[fldoptiond];
}
this code is not working --> $characters = array($optiona,$optionb,$optionc,$optiond);

but if i will put directly the value like this --> $characters = array("sample option A","sample option B","sample option C","sample option D");
it works fine.


........ this part here below is working fine........
$keys = array();
while(count($keys) < 7) {
$x = mt_rand(0, count($characters)-1);
if(!in_array($x, $keys)) {
$keys[] = $x;
}
}
foreach($keys as $key){
$random_chars .= $characters[$key].<br>;
}
echo $random_chars;
...........................................................................

Guys I really need your help about this.... Thanks in advance... God Bless you all...

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).