简体   繁体   English

在php mysql中显示所选用户的记录

[英]Display the record of selected user in php mysql

I m trying to display the records of 2 tables in a single table using php and mysql. 我正在尝试使用php和mysql在一个表中显示2个表的记录。 I have 2 tables member and payment 我有2张桌子的会员和付款

member 会员

id | name |.....
----------
101 | abc |..

and payment table contains 付款表包含

id | uid | amount
----------
1 | 101 | 1200

i want to display the record of entered no.My table displays all the rows. 我想显示输入编号的记录。我的表显示所有行。 I want to display the record of only 1 number. 我只想显示1个数字的记录。

here is the code.. This is page1 where user as to enter a number and the records of dat number as to display in second page. 这是代码。这是第1页,用户在其中输入数字,数据记录在第二页中显示。

<form method="post" action="reportdet2.php">
<label type="text" name="name" maxlength="50" size="30" class="label">Enter the Membership Number which You waant to edit</label><br />
<input type="text" name='id' placeholder="enter Membership Number" class="input" size="40"/><br />
<span class="field">(* Required field)</span><br /><br />
<input type="hidden" name='uid' placeholder="" class="input" size="40"/><br />

<input type="submit" name="submit" value="SUBMIT" class="button"><br /><br /><br /><br />
</form>
</body>
</html>

page2 第2页

    <?php
    mysql_connect("localhost","root","");
    mysql_select_db("anthonys");
    if(isset($_POST['submit']))
    {
    $id= $_POST['id'];

    if( ! ctype_alnum($id) )
      die('invalid id');
    $uid=$_POST['uid'];

    $query="SELECT m.id, m.fathername, m.mothername
    FROM member m JOIN payment p ON m.id = p.uid";



    if(mysql_num_rows($run)>0){
    echo "<script>window.open('reportdet2.php','_self')</script>";
    }

    else {

        echo "<script>alert('Membership No is Invalid!')</script>";
        }
    }
    ?>


<th>No</th>
<th>Name</th>


<th>UID</th>

<th>Amount</th>

</tr>


<?php
$id="";
$id=$_REQUEST["id"];

$uid=$_REQUEST["uid"];
mysql_connect("localhost","root","");
mysql_select_db("anthonys");
$query="SELECT m.id, m.fathername, m.mothername
FROM member m JOIN payment p ON m.id = p.uid";

$run= mysql_query($query);






while($row=mysql_fetch_array($run))
{
$id=$row[0];
$name=$row[1];
$uid=$row[2];

$amount=$row[3];


?>

<tr align='center'>
<td><?php echo $id; ?></td>

<td><?php echo $name; ?></td>
<td><?php echo $uid; ?></td>

<td><?php echo $amount; ?></td>



</tr>
<?php } ?>
</table>

<?php
        $result = mysql_query("SELECT sum(amount) FROM payment") or die(mysql_error());
        while ($rows = mysql_fetch_array($result)) {
    ?>
    <div class="pull-right">
        <div class="span">
            <div class="alert alert-success"><i class="icon-credit-card icon-large"></i>&nbsp;Total:&nbsp;<?php echo $rows['sum(amount)']; ?></div>
        </div>
    </div>
    <?php }
    ?>
</body>
</html>

Add a WHERE m.id = $id clause to your SQL queries to only show the record(s) that match $id . 在您的SQL查询中添加WHERE m.id = $id子句,以仅显示与$id匹配的记录。

Note that your (example) scripts are susceptible for all kinds of nasty attacks... I do not know whether your actual application has safety measures to prevent SQL injection , etc.. If not, you might want to add them ! 请注意,您的(示例)脚本容易受到各种讨厌的攻击...我不知道您的实际应用程序是否具有防止SQL注入等的安全措施。如果没有,您可能想要添加它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM