simplify the code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mit
Forum Commoner
Posts: 32
Joined: Mon Sep 15, 2008 6:37 am

simplify the code

Post 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;

}
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: simplify the code

Post by VladSun »

[sql]SELECT    questionFROM    questionORDER BY    rand()LIMIT     3[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply