如何将两个不同的表中的两个值输出到href?

时间:2018-03-19 02:42:54

标签: php mysql pdo

我想输出这样的东西:

viewlogs.php ID = 1和;为employeeno = 15000000600

但是,我不确定我应该使用什么条件。我有两个独立的数据库可以调用,一个是在MySQL上,很容易被带到localhost,而MSSQL我不是很熟悉。

我正在尝试使用&&amp ;;在一个循环中。

我的代码是这样的:

<?php
session_start();
    if (!isset($_SESSION['username']))
    {
        header('location: login.php');
    die();
    }


?>

 <?php 

try {

    include ("config.php");
    include ("sqlsrv.php");
 }catch(Exception $e){
    die("ERROR:".$e->getMessage());
 } 

if(isset($_POST['usn']) && $_POST['usn']!=""){ 
     $res = $conn->prepare("SELECT EmployeeNo, FirstName, MiddleName, LastName, DateHired, ResignationDate FROM TA3.dbo.Employees");
     $res->execute();

     $req = $db->prepare("SELECT * FROM students WHERE usn LIKE :usn");
     $req->execute(array(
        'usn'=>'%'.$_POST['usn'].'%'));

     if ($req->rowCount()==0 && $_SESSION['type']=="Super_Admin") { ?>


        <span class="notfound">Student not found? <a class="addstud" href="create.php">add student?</a></span>

        <?php

     }
        elseif ($req->rowCount()==0 && $_SESSION['type']=="Admin") { ?>

            <span class="henhen">Student not found</span>

     <?php
        }
     else{
        while ($data=$req->fetch() && $outcome=$res->fetch()){
            ?>


        <div class="infohen">Info </div>
        <div class="uy">    
        <div class="name"><?php echo $data['fname']." ".$data['mname']." ".$data['lname']; ?></div> 
        <div class="email"><?php echo $data['email']; ?></div> 

        <div class="usn"><?php echo $data['usn']; ?></div>

        <div class="schedule"><?php echo $data['schedule']; ?></div>
        <div class="strand"><?php echo $data['strand']; ?></div></div>


        <?php if ($_SESSION['type']=="Super_Admin")
        { ?>
        <div class="gridme">
            <div class="action-list">
        <div class="action">Action</div>    
        <div class="edit"> <a href="edit.php?id=<?= $data['id']; ?>">Edit</a></div>
        <div class="logs"><a href="viewlogs.php?id=<?= $data['id']; ?>&EmployeeNo=<?= $outcome['EmployeeNo'];?>">Logs</a></div>
        <?php } else { ?>
        <div class="gridme">
            <div class="action-list">
        <div class="action">Action</div>    
        <div class="logs"><a href="viewlogs.php?id=<?= $data['id']; ?>&EmployeeNo=<?= $outcome['EmployeeNo'];?>">Logs</a></div>
        <?php } ?>
        </div>
    </div>




            </div>
            </div>


    <?php
    }
}

}else { ?>


    <span class="message">Enter USN!</span>

    <?php
}


?> 




 <!-- <div class="enable"> <a onclick="return confirm('Are you sure you want to Enable student?')" href="enable.php?id=<?= $data['id']?>"> Enable </div>
        <div class="disable"> <a onclick="return confirm('Are you sure you want to disable student?')" href="disable.php?id=<?= $data['id']?>">Disable</a>
            </div> -->
     <!--   </div>
        <div class="status-list">
        <div class="status">Status</div>
        <div class="active">Active</div>
        </div> -->

如果我使用while($ data = $ req-&gt; fetch()&amp;&amp; $ outcome = $ res-&gt; fetch()),则从$ data调用的详细信息都已消失。

我遇到逻辑问题,因为我不太擅长逻辑。

1 个答案:

答案 0 :(得分:0)

如果有人可能需要它,我找到了解决方案。

我只需要使用开括号和右括号。

while(($ data = $ req-&gt; fetch())&amp;&amp;($ outcome = $ res-&gt; fetch()))