0

Can someone teach me how to populate this table with different data from same sql table but result will be session user wise but admin will get merged result , below code IS CORRECT BUT THE PROBLEM IS ADMIN CANT GET USER DATA IN THE TABLE ; IS THERE ANY WAY TO IMPLEMENT $select = $pdo->prepare("SELECT * FROM tbl_invoice WHERE created_by = '".$_SESSION['user_id']."' ORDER BY invoice_id DESC"); FOR USER AND $select = $pdo->prepare("SELECT * FROM tbl_invoice ORDER BY invoice_id DESC"); FOR ADMIN. [PAGE AND TABLE WILL BE SAME]

<tbody>
                        <?php
                        $no = 1;
                        $select = $pdo->prepare("SELECT * FROM tbl_invoice WHERE created_by = '".$_SESSION['user_id']."'  ORDER BY invoice_id DESC");
                        $select->execute();
                        while($row=$select->fetch(PDO::FETCH_OBJ)){
                        ?>
2
  • Why not just do the second query if the user is admin? That will contain all data anyways. Something like (pseudo code) if ($_SESSION[’user’]==admin) { $select = [SELECT ALL QUERY] } else { $select = [SELECT WHERE CREATED BY QUERY] } Commented Jan 6, 2020 at 6:31
  • If you are going to use a prepared statement, use a placeholder too (?) and pass the data to the execute() call. Commented Jan 6, 2020 at 6:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.