• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

while ($php_row = mysql_fetch_object($php_resultID)) Help

I have the following SQL statement which runs fine as a raw SQL query.  But when I put it into my PHP script I can't seem to access the u_owned_by.full_name element.

Here is my SQL statement:

select t.created_on_date, t.check_status_on_date, t.due_on_date, t.id, t.title, u_owned_by.full_name, u_assigned_to.full_name, c_category.category, s_subcategory.subcategory, t.description, t.comments
from ralph_Tasks t, ralph_Cat c, ralph_Sub s
left join ralph_Users u_owned_by on u_owned_by.id = t.owned_by
left join ralph_Users u_assigned_to on u_assigned_to.id = t.assigned_to
left join ralph_Cat c_category on c_category.id = t.category
left join ralph_Sub s_subcategory on s_subcategory.id = t.subcategory;

Here is my PHP part:
while ($php_row = mysql_fetch_object($php_resultID))
        <?php echo $php_row->u_owned_by.full_name?>

All I see on the web page is 'full_name' instead of the actual name I see when I run the SQL query.  So, I guess I don't have the php access part right.
1 Solution
try this..

while ($php_row == mysql_fetch_object($php_resultID)){
        echo $php_row=>u_owned_by.full_name;
while ($php_row = mysql_fetch_object($php_resultID))
        <?php= $php_row->full_name?>
don't refere to table's name, just column's name
rfreshAuthor Commented:
>don't refere to table's name, just column's name

The full_name field is in the Users Table.  Tasks fields Category and SubCategory are INT indexes pointing to full_name in Users.  Thus

u_owned_by.full_name, u_assigned_to.full_name

In Tasks Table, one record shows owned_by a value 5 which in Users matches the ID value of 5 for full_name == Ralph.  In Tasks, assigned_to shows value of 8 which in Users table show index of 8 has full_name == Steve.  So, I need to distungish specifically for each one.  That's way I had

 <?php echo $php_row->u_owned_by.full_name?>

but it wasn't working.  BTW when I  used full_name only it worked for owned_by but not assigned_to - when I used full_name only, both showed the same text value (Ralph).

why dun u use "as"
i meant  u_owned_by.full_name as owned_full_name, u_assigned_to.full_name as assigned_full_name

and then
echo $php_row->owned_full_name

PHP is not mySQL, within PHP, you CAN'T refere to table's name, you must give your field a unique name using "as"

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now