-
Notifications
You must be signed in to change notification settings - Fork 0
/
emp_query_sql.php
58 lines (46 loc) · 1.28 KB
/
emp_query_sql.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//show errors
error_reporting(E_ALL);
ini_set("display_errors", 1);
//establish connetcion to DB
$mysqli = new mysqli("localhost", "web", "10paper", "PAYROLL");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$ID=$_POST['ID'];
$myq = "SELECT * FROM EMPLOYEE WHERE ID='" . $ID . "';";
echo $myq . "</br>";
$result = $mysqli->query($myq);
?>
Contents of employee table</br>
<table border="1">
<tr>
<?php
$numOfCols = $mysqli->field_count;
echo "Columns:" . $numOfCols . "/<br>";
//$numOfRows = mysql_num_rows($result);
while($finfo = mysqli_fetch_field($result))
echo "<th>" . $finfo->name . "</th>";
/*for($i=0; $numOfCols > $i; $i++)
{
echo "<th>" . mysql_field_name($result, $i) . "</th>";
}*/
?>
</tr>
<tr>
<?php
$result->data_seek(0); //moves internal pointer to 0, fetch starts here
while ($row = $result->fetch_array(MYSQLI_NUM)) //fetch num array && pointer++
{
for($fieldCounter=0; $numOfCols > $fieldCounter; $fieldCounter++)
{
echo "<td>${row["$fieldCounter"]}</td>";
}
}
?>
</tr>
</table>