开发者

Click name from one mysql table to show report from another table

I have a table with the following fields: email - name - username - userid currently the data in this table is pulled into a html table.

In a seperate table i have all the user's data / information.

What i would like to do is click on a name from the first table (consisting of email - name - username)

And have that users information shown on its own like a report generation.

Both the tables have the same unique userid's applied so could someone enl开发者_开发知识库ighten me as to the best way to do this?

Thanks.


Surround the name with an anchor tag that has the id as some parameter.

I'd do it with 2 templates where one lists all the users (userList.php) and the other one shows detailed information about a user (userInformation.php).

userList.php:

<table>
    <tr>
        <th>
            <a href="userInformation.php?id=<?php echo $user->id;?>">
                <?php echo $user->username;?>
            </a>
        </th>
        <td><?php echo $user->email;?></td>
        <td><?php echo $user->propN;?></td>
    </tr>
    ...
    ...
</table>

userInformation.php:

<?php
    $userId = $_POST['id'];
    $user = someFunctionForGettingTheUserPerhaps($userId);
?>

<table>
    <tr>
        <th><?php echo $user->username;?></th>
        <td><?php echo $user->email;?></td>
        <td><?php echo $user->password;?></td>
        <td><?php echo $user->name;?></td>
        <td><?php echo $user->propN;?></td>
        ...
        ...
    </tr>
</table>

EDIT: Replaced '.' with '->' since the latter is the property accessor notation in PHP.


Set the onclick attribute of each table row to

echo('<tr onclick="location.href=\'userdet.php?id='.$row['userid'].'\'">

Where userdet.php is a page that puts the information you want into a HTML table.

edit

You could also try putting the data in like this http://www.jsfiddle.net/dduncan/UuA9E/ although that could get slow if you have a massive users table. (click the table row)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜