lundi 19 mars 2018

While loop with two if conditions? Last condition only always output '1'?

I have three tables to connect on a single page. The first statement

if (($outcome['EmployeeNo'] = $data ['usn']

shows the numbers we need but the second one only outputs the number '1'.

($outcome['EmployeeID'] = $out['EmployeeID'])):

I'm using this to output them in href.

(viewlogs.php?id=<?= $data['id']; ?>&EmployeeNo=<?= $outcome['EmployeeNo'];?>&EmployeeID=<?= $out['EmployeeID'];)

but my condition is incorrect as it only shows outcome or out = 1.

Does anyone have a suggestion for this?

My complete codes:

 <?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']!=""){ 

         $re = $conn->prepare("SELECT EmployeeID, TimeLogID, RecordDate, RecordTime, Type, ActualTime FROM TA3.dbo.TimeLogs");
         $re->execute();

         $res = $conn->prepare("SELECT EmployeeNo, FirstName, MiddleName, LastName, DateHired, ResignationDate, EmployeeID 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()) 
               && ($out=$re->fetch())){

                if (($outcome['EmployeeNo'] = $data ['usn']) && ($outcome['EmployeeID'] = $out['EmployeeID'])):

            ?>


            <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'];?>&EmployeeID=<?= $out['EmployeeID'];?>">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'];?>&EmployeeID=<?= $out['EmployeeID'];?>">Logs</a></div>
            <?php } 
            endif; ?>
            </div>
        </div>




                </div>
                </div>


        <?php
        }
    }

 }else { ?>


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

        <?php
    }


  ?>

Aucun commentaire:

Enregistrer un commentaire