PHP Echo记录基于指定的ID

时间:2014-11-09 04:36:09

标签: php mysql sql row

所以我需要一种能够echo $row['username']echo $row['password']指定id的方法。

例如,我有3行,我需要从身份号码20,56,88获取信息。 现在我已经进行了查询$query = "SELECT * FROM Card_File WHERE id = $id";

我如何回应这些数据(记住它不在表格中,可以放在网页上的随机位置,输出将进入的表格将是不同的(例如,没有相同的表格字段)的名称。))

echo $row['username'] $id=20;
echo $row['password'] $id=20;

echo $row['username'] $id=56;
echo $row['password'] $id=56;

echo $row['username'] $id=88;
echo $row['password'] $id=88;

我一直在寻找周围并看到一些非常复杂的例子,但不要相信它很难用id回应一行。我可能错了

下面不是最终结果的一个很好的例子,但会给你一个想法。



<!DOCTYPE html>
<html>
    <head>

        <?php
        // Connect to the database
        $link = mysqli_connect('localhost','root','pass','ACS_SHAREPOINT_ADDONS');
        // Select table and arguments
        $query = "SELECT * FROM Card_File WHERE id = $id";
        $result = mysqli_query($link, $query);
        ?>

    </head>



    <body>
        <?php foreach($row = mysqli_fetch_array($result)): ?>
        <div class="loginForms">
            <form target="_blank" action="https://www.website.com" method="post">
                <input type="hidden" name="username" id="auth-form-login" value="<?php $id=20 echo $row['username']; ?>"/>
                <input type="hidden" name="password" id="auth-form-pass" value="<?php $id=20 echo $row['password']; ?>"/>
                <input type="hidden" name="redirDocument" value="user"/>
                <input type="hidden" name="query" value=""/>
                <input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
                <input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
            </form>
        </div>

<div class="loginForms">
            <form target="_blank" action="https://www.website.com" method="post">
                <input type="hidden" name="username" id="auth-form-login" value="<?php $id=56 echo $row['username']; ?>"/>
                <input type="hidden" name="password" id="auth-form-pass" value="<?php $id=56 echo $row['password']; ?>"/>
                <input type="hidden" name="redirDocument" value="user"/>
                <input type="hidden" name="query" value=""/>
                <input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
                <input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
            </form>
        </div>

<div class="loginForms">
            <form target="_blank" action="https://www.website.com" method="post">
                <input type="hidden" name="username" id="auth-form-login" value="<?php $id=88 echo $row['username']; ?>"/>
                <input type="hidden" name="password" id="auth-form-pass" value="<?php $id=88 echo $row['password']; ?>"/>
                <input type="hidden" name="redirDocument" value="user"/>
                <input type="hidden" name="query" value=""/>
                <input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
                <input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
            </form>
        </div>

        <?php endforeach; ?>
    </body>

</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我相信这就是你想要做的。

   <?php 
    $ids_tofind = array(1,6,3); //for example
    $id = implode(",",$ids_tofind);

    $link = mysqli_connect('localhost','root','pass','ACS_SHAREPOINT_ADDONS');
    // Select table and arguments
    $query = "SELECT * FROM Card_File WHERE id IN(". $id.")";
    $result = mysqli_query($link, $query);

    while($row = mysqli_fetch_array($result)){;?>

       <div class="loginForms">
        <form target="_blank" action="https://www.website.com" method="post">
            <input type="hidden" name="username" id="auth-form-login" value="<?php echo $row['username']; ?>"/>
            <input type="hidden" name="password" id="auth-form-pass" value="<?php echo $row['password']; ?>"/>
            <input type="hidden" name="redirDocument" value="user"/>
            <input type="hidden" name="query" value=""/>
            <input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
            <input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
        </form>
       </div>

     <?php };?>

这将回显ID为1,6和3的所有三个用户的表单。