Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do we reference a specific record from related records? #201

Closed
ChrissDeGrece opened this issue Dec 12, 2013 · 1 comment
Closed

How do we reference a specific record from related records? #201

ChrissDeGrece opened this issue Dec 12, 2013 · 1 comment

Comments

@ChrissDeGrece
Copy link

In the following example I need to output the description for user_info(user_id=1,title=Public) like echo $infos->???????

Is there any way to get this record?

Thanks

Table : Users , PK: user_id
---------------------------------
| user_id       |   username    |
---------------------------------
|  1            |   user1       |
|  2            |   user2       |
---------------------------------
Table: user_info , PK: id , UNIQUE_INDEX: user_id + title
-----------------------------------------------------------------------------
|id             | user_id       |   title       |  description              |
-----------------------------------------------------------------------------
| 1             |   1           |   Public      |  Detailed info for user 1 |
| 2             |   1           |   Private     |  More details for user 1  |
| 3             |   2           |   Public      |  Some secret stuff        |
-----------------------------------------------------------------------------
<?php 
    $user = new User(1);
    $infos = $user->buildUserinfos();
?>
<form action="" method="post">
    <fieldset>
        <p>
            <label for="username">Username</label>
            <input type="text" id="username" name="username" />
        </p>
        <p>
            <input type="hidden" name="userinfos::user_id[]" value="1">
            <input type="hidden" name="userinfos::title[]" value="Public">
            <label for="info_description">Public Info</label>
            <input type="text" id="info_description" name="userinfos::description[]" value="<?php echo $infos->??????? ;?>" />
        </p>
        <p>
            <input type="hidden" name="userinfos::user_id[]" value="1">
            <input type="hidden" name="userinfos::title[]" value="Private">
            <label for="info_description">Private Info</label>
            <input type="text" id="info_description" name="userinfos::description[]" value="<?php echo $infos->??????? ;?>" />
        </p>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
</form> 
@ChrissDeGrece
Copy link
Author

OK got it:

$infos->filter(array('getTitle='=>'Private'))->getRecord(0)->getDescription()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant