Link to home
Start Free TrialLog in
Avatar of rfresh
rfresh

asked on

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.
Avatar of theed
theed

try this..

<?php
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
Avatar of rfresh

ASKER

>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).

ASKER CERTIFIED SOLUTION
Avatar of hiteshgupta1
hiteshgupta1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PHP is not mySQL, within PHP, you CAN'T refere to table's name, you must give your field a unique name using "as"