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>
Fetching from an array into html tales - help!!!
Moderator: General Moderators
-
mrwaterfield
- Forum Newbie
- Posts: 3
- Joined: Wed Oct 27, 2004 4:15 am
Hi there
in your code
Also, note that you have an extra semi-colon on this line
Hope this helps
in your code
lines 1, 2 and 3 end with a fullstop - which in PHP is the string concatenation character. Replace these with the semi-colon (the statement terminator) and all should be well.Code: Select all
$emp_id = $empArray['employee_id']. $name = $empArray['name']. $job = $empArray['job']. $dep_id = $empArray['department_id'];
Also, note that you have an extra semi-colon on this line
It should beecho;"</table>";
Code: Select all
echo "</table>";- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Code: Select all
while($empArray = mysql_fetch_array($result))Code: Select all
while($empArray = mysql_fetch_assoc($result))http://www.php.net/manual/en/function.extract.php
Last edited by CoderGoblin on Wed Oct 27, 2004 6:39 am, edited 1 time in total.
problem in your code
you have to use like this,
while($empArray = mysql_fetch_array($result,MYSQL_ASSOC))

while($empArray = mysql_fetch_array($result,MYSQL_ASSOC))