Fetching from an array into html tales - help!!!
Posted: Wed Oct 27, 2004 4:39 am
I am trying to fetch info from my 'employee' mysql db into an html table using arrays. However, in the first column I get all the variables about the employee ie (ie employee id, name, job, dep id), in the next three variables ie (ie name, job, dep id) two in the next then only the required info in the dep id column. Can anyone tell me how to stop this...I've been at it for hours now without a breakthru!
Thanks
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost","root","*****")or die(mysql_error());
echo $conn;
mysql_select_db("employee",$conn);
$sql = "SELECT * FROM employee" or die(mysql_error());
$result=mysql_query($sql,$conn)or die(mysql_error());
echo"<table><tr><th>Employee ID</th><th>Name</th>
<th>Job</th><th>Department ID</th></tr>";
while($empArray = mysql_fetch_array($result))
$emp_id = $empArray['employee_id'].
$name = $empArray['name'].
$job = $empArray['job'].
$dep_id = $empArray['department_id'];
echo "<tr><td>$emp_id</td><td>$name</td><td>$job</td><td>$dep_id</td></tr>";
echo;"</table>";
mysql_close($conn);
?>
</body>
</html>
Thanks
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost","root","*****")or die(mysql_error());
echo $conn;
mysql_select_db("employee",$conn);
$sql = "SELECT * FROM employee" or die(mysql_error());
$result=mysql_query($sql,$conn)or die(mysql_error());
echo"<table><tr><th>Employee ID</th><th>Name</th>
<th>Job</th><th>Department ID</th></tr>";
while($empArray = mysql_fetch_array($result))
$emp_id = $empArray['employee_id'].
$name = $empArray['name'].
$job = $empArray['job'].
$dep_id = $empArray['department_id'];
echo "<tr><td>$emp_id</td><td>$name</td><td>$job</td><td>$dep_id</td></tr>";
echo;"</table>";
mysql_close($conn);
?>
</body>
</html>