Page 1 of 1

printing value of SELECT table.name AS alias

Posted: Thu Mar 02, 2006 9:53 am
by bwv2
It may be that it's early in the morning, but I can't get my brain to wrap around this simple concept. Here's my mySQL query:

Code: Select all

$sql="
SELECT mytable.capacity AS 'capacity', yourtable.name AS 'name'
FROM mytable, yourtable
WHERE mytable.id=$myId AND yourtable.id=$yourId";
$result=mysql_query($sql, $conn);
Pretty simple. Now I want to print the values of "capacity" and "name" to the screen. I know this is very simple, but I just can't seem to get it.

Posted: Thu Mar 02, 2006 10:02 am
by Grim...
One way:

Code: Select all

$sql="
SELECT mytable.capacity AS 'capacity', yourtable.name AS 'name'
FROM mytable, yourtable
WHERE mytable.id=$myId AND yourtable.id=$yourId";
while ( $a_row = mysql_fetch_object( $sql ) )
{
    print $a_row->capacity." - ".$a_row->name;
}