Page 1 of 1

simplify the code

Posted: Mon Jan 12, 2009 3:13 am
by mit
I have this function which is not working right now
how can i simplify it and return 3 values such as $Q1,$Q2,$Q3 to the other page.
thx

function questions($random1,$random2,$random3){
global $dbhandler;
$sql = " SELECT DISTINCT(question) as Q1 FROM question where id='$random1'";
$res = $dbhandler->query($sql);
$Q1=$res[0]['Q1'];
$sql = " SELECT DISTINCT(question) as Q2 FROM question where id='$random2'";
$res = $dbhandler->query($sql);
$Q2=$res[0]['Q2'];
$sql = " SELECT DISTINCT(question) as Q3 FROM question where id='$random3'";
$res = $dbhandler->query($sql);
$Q3=$res[0]['Q3'];
return $res;

}

Re: simplify the code

Posted: Mon Jan 12, 2009 3:17 am
by VladSun
[sql]SELECT    questionFROM    questionORDER BY    rand()LIMIT     3[/sql]