neutrall Level: Scholar

 Registered: 28-03-2004 Posts: 43
|
Simplified SQL command
I have the following function in a class :
<?php
function RaceName() {
//Return the User Name
$id = $this->Id;
//Fetch the user race Id
$sql = "SELECT Race_Id FROM User WHERE Id=$id";
$result = $this->db->query($sql);
$row = $result->fetch();
$raceid = $row['Race_Id'];
//Fetch the race Name
$sql = "SELECT Name FROM Races WHERE Id=$raceid";
$result = $this->db->query($sql);
$row = $result->fetch();
return $row['Name'];
} ?>
|
I'm sure they is a way to have only one SQL statement, can anyone give me a hand?
This is what I tried, but it didn't work :
<?php $sql = "SELECT Name FROM Races, User WHERE User.Id=$id AND Id=User.Race_Id"; ?>
|
Any sugestion?
____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.
|