Jump to content

help putting data from multiple tables into an array


whypie

Recommended Posts

i am trying to get data from two tables and put them into an array that i can return to my template. - i should mention that im quite new to php.

 

here are my tables:

 

horses:

 

id, name, owner_id

 

owners:

 

id, name

 

i have a function called get_horses() that returns details on all of the horses, but i want it to also get the owner name and put that into the array, how can i do this?

 

 

  1. class horse_details {

  2.   

  3.    function get_horses(){

  4.        $query = "SELECT * FROM horses";

  5.        $result = mysql_query($query);

  6. 

  7.        $horses = array();

  8. 

  9.        while($tmp = mysql_fetch_assoc($result)) {

  10.            $horses[] = $tmp;

  11.        }

  12. 

  13.        return $horses;

  14.    }

  15. 

  16. }

 

my template:

 

  1. {foreach item=horse from=$horses}

  2. <tr>

  3.    <td>{$horse.name}</td>

  4.    <td>{$horse.breed}</td>

  5.    <td><a href="owners.php?action=view&owner_id={$horse.owner_id}">{$i.want.the.owner.name.here}</a></td>

  6. </tr>

  7. {foreachelse}

  8. <tr>

  9.    <td colspan="3">No items were found</td>

  10. </tr>

  11. {/foreach}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.