printing value of SELECT table.name AS alias

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

printing value of SELECT table.name AS alias

Post 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.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

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