-2

I am displaying few values in the table from the database, the while loop works properly anywhere outside the table, but inside the table it is displaying nothing. I have added the entire code as advised, I have provided the sql queries which I used and also the entire HTML Form. I have tried all the code changes and nothing helps.

<!doctype html>
<?php
include ("connect.php");
session_start();
$getid=mysqli_real_escape_string($db,$_GET['key']);
$username=$_SESSION['login_user'];
unset($_SESSION['getid']);  
$_SESSION['getid']=$getid;

$userinfo="select * from users_master where username='$username'";
$result=mysqli_query($db, $userinfo);

$task = "select * from task_master where id='$getid'";
$result1=mysqli_query($db, $task);

$task_assigned_to="select * from task_assigned_to where id='$getid'";
$result2=mysqli_query($db, $task_assigned_to);

$task_follow="select * from task_followers where id='$getid'";
$result3=mysqli_query($db, $task_follow);

?>
<html>
<head>
<meta charset="utf-8">
<title>Task Info</title>
<link rel="stylesheet" href="style/style.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="fontawesome/css/all.css">

<script type="text/javascript">
function myFunction() {
    
    var left = (screen.width/2)-(450/2);
var top = (screen.height/2)-(450/2);
    let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,
width=800,height=300,left=`+top+`,top=`+top;

  window.open('closurepopup.html','test',params);
}
</script>
</head>
<body>
<form name="followupform" action="controllers.php" method="POST">
<input type="hidden" name="taskfollowupid" value="<?php echo $getid; ?>"
<div class="title1">
    <a href="closurepopup.html"><button type="button" name="btnclosetask" class="btn btn-primary">Complete</button></a>
    <a href="extenddeadline.php?key=<?php echo $getid; ?>"><button type="button" name="btnextenddeadline" class="btn btn-info">Extend deadline</button></a>
    <a href="edittask.php?key=<?php echo $getid; ?>"><button type="button" name="btnedittask" class="btn btn-info">Edit Task</button></a>
    </div>
<br>
<div>
    <?php while ($row=mysqli_fetch_array($result1,MYSQLI_ASSOC))
{
    ?>
    <i class="fa fa-star fa-2x" aria-hidden="true"><?php echo "#". $row['id']." " .$row['tasktitle']; ?></i>
<?php } ?>
</div>
<br>

<table class="table table-bordered">    
<tr>
        <th>Task Assigned by</th>
        <td><?php 
while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC))
{
    echo $row['first_name']. " " .$row['last_name'];  }?></td>
    </tr>
    <?php
    while ($row1=mysqli_fetch_array($result1))
    {
        echo print_r($row) & print_r($row2);
        ?>
<tr>    
        <th>Status</th>
        <td><?php echo $row1['status']; ?></td>
    </tr>
    <tr>
        <th>Description</th>
        <td><?php echo $row1['description']; ?></td>
    </tr>
    
    <tr>
        <th>Deadline</th>
        <td><?php echo $row1['deadline']; } ?></td>
    </tr>
    
    <tr><th>Task Assigned to</th>
    <td>
    <?php
while($row2=mysqli_fetch_array($result2,MYSQLI_ASSOC))
{
    echo $row2['first_name']." ".$row2['last_name'].'; &nbsp;'; 
}
        ?>
        </td></tr>
</table>
<table class="table table-bordered">
    <tr>
        
        <th>Followed By</th>
        <td>
        <?php
            while($row3=mysqli_fetch_array($result3, MYSQLI_ASSOC))
            {   
                echo $row3['first_name']. " " .$row3['last_name'].'; &nbsp;'; 
            }
            ?>  
            </td>
    </tr>
</table>
    <textarea rows="2" cols="80" name="followupmess" placeholder="Followup message"></textarea><br>
    <button type="submit" name="btnsendfollowup" class="small">Send Followup</button><br>
    </form>
    <?php
    $followup = "select * from followup_messages where id='$getid'";
    $result3=mysqli_query($db,$followup);
    while ($row3=mysqli_fetch_array($result3))
    {
        ?>
        <table class="table table-bordered">
<tr>
        
        <th>Sent by</th>
        <td><?php echo $row3['first_name']. " " .$row3['last_name']; ?></td>
    </tr>
    <tr>
        
        <th>Sent on</th>
        <td><?php echo $row3['created_at']; ?></td>
    </tr>
    <tr>
        
        <th>Message</th>
        <td><?php echo $row3['message']; ?></td>
    </tr>
</table>
    <?php
    }
    ?>  
kirupaji
  • 1
  • 4
  • what errors it shows?? – KUMAR Nov 12 '20 at 12:22
  • please close while loop at end. – KUMAR Nov 12 '20 at 12:22
  • remove `MYSQLI_ASSOC`. – KUMAR Nov 12 '20 at 12:23
  • Are you sure your query returns records? Also are you sure you didn't misspelled the name of a column? Could you try to add this line right before the `?>`: `echo "
    ";print_r($row1);echo "
    ";` ? This will help you debug your code.
    – KodeFor.Me Nov 12 '20 at 12:23
  • Hi guys, I am not receiving any mysqli errors, I closed the while loop in the end, anyhow will try the above comments and get back – kirupaji Nov 12 '20 at 12:26
  • `print_r($row1);` show us what it returns?? – KUMAR Nov 12 '20 at 12:28
  • I really recommend not mixing html with php code, separate logic into different file and then only use the data calculated in file –  Nov 12 '20 at 12:29
  • I didn't received any errors, please see the entire code
    – kirupaji Nov 12 '20 at 12:31
  • you added database connection in it?? – KUMAR Nov 12 '20 at 12:32
  • yes I added, the rest of the code are working fine, only this particular block displaying nothing, the database table contains all the values – kirupaji Nov 12 '20 at 12:34
  • `print_r($row);` & `print_r($row2);` – KUMAR Nov 12 '20 at 12:36
  • it displays nothing, I don't know where I am struck with. – kirupaji Nov 12 '20 at 12:40
  • write your full code wuth sql queries please. – KUMAR Nov 12 '20 at 12:41
  • Hi, I have updated the complete page. – kirupaji Nov 12 '20 at 12:54
  • var_export() or var_dump() might be better than print_r(). Just in case you're dealing with false or null values. – Torbjörn Stabo Nov 12 '20 at 13:01
  • Are you certain that `$_SESSION['login_user']` contains something?! `session_start();` has to come before any output - your code already fails at this requirement – brombeer Nov 12 '20 at 13:12
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Nov 12 '20 at 13:30

1 Answers1

0

var_dump(), gives me the results when it is in the outerloop, so I switched the while loop to the top most part of the code and it worked. Thank you all.

kirupaji
  • 1
  • 4