Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

How would I programmatically loop through employees ( a SQL Table) and display each name as <li> element and sort them by LastName? 
                   

 Example:                               
                               foreach ($employees as $emp) {
                                   echo '<li class="mdl-list__item">';
                                   echo $emp['FirstName'];
                                   echo '</li>'; 
                               }
                               
                         

Expert Solution
Check Mark
Step 1

Required source code :-

Solution :- i am writing the required php code where we fetch the detail of table - Employees(name of employees order by LastName) and print it in <li> list of html content.....

--------------------------------------------------------------------------------------

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

// this sql query gives the name of employees in sorted order by last name 
$sql = "SELECT Firstname, Lastname FROM Employees ORDER BY Lastname";
$employees = mysqli_query($conn, $sql);

if (mysqli_num_rows($employees) > 0) {
    
  // output data of each row
  
   foreach ($employees as $emp) {
       echo "<li class="mdl-list__item">";
       echo $emp['FirstName'];
       echo $emp['LastName'];
       echo "</li>"; 
    }
  
} else {
  echo "0 results";
}

mysqli_close($conn);
?>

Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY