-1

I am trying to display table data using PHP however for an unknown reason the result I am getting is not what I expected. I am aiming to display a table with the data from the database inside it however I am instead seeing the table with the variable names inside but no data, and above the table I see the word echo repeated. The code I am using is as follows;

<?php
//connect to database
mysql_connect('mysqlhost3', '40099609', 'ou2wareyido');
mysql_select_db('40099609'); 

$sql="SELECT * FROM gig";

$records=mysql_query($sql);


?>

<html>
<head>
<title> Gig Data </title>
</head>

<body>

<table width="600" border="1" cellspacing="1">
<tr>
<th> ID </th>
<th> Start Time </th>
<th> Name </th>
<th> Venue </th>
<th> Act </th>
<th> Img </th>


</tr>
<?php
while ($employee=mysql_fetch_assoc($records)){
echo "<tr>";

echo"<td>".$id['ID']."</td>";
echo"<td>".$start['Start Time']."</td>";
echo"<td>".$sname['Name']."</td>";
echo"<td>".$venue['Venue']."</td>";
echo"<td>".$act['Act']."</td>";
echo"<td>".$img['Img']."</td>";
echo "</tr>";

}
?>
</table>
</body>
</html>

Can anyone see where I am going wrong ?

Jocelyn
  • 11,209
  • 10
  • 43
  • 60
LewDawg
  • 5
  • 1
  • 2

2 Answers2

1

You are gonna need a space after echo in your data lines. Also your associative array is called $employee:

echo "<td>".$employee['ID']."</td>";
echo "<td>".$employee['Start Time']."</td>";
echo "<td>".$employee['Name']."</td>";
echo "<td>".$employee['Venue']."</td>";
echo "<td>".$employee['Act']."</td>";
echo "<td>".$employee['Img']."</td>";
Arth
  • 12,789
  • 5
  • 37
  • 69
0

You're using a whole whack of undefined variables. Since you're fetching your db results into $employee, shouldn't it be more like:

while ($employee=mysql_fetch_assoc($records)){
echo "<tr>";
echo"<td>".$employee['ID']."</td>";
            ^^^^^^^^^---note "new" var
echo"<td>".$employee['Start Time']."</td>";
            ^^^^^^^^^---note "new" var

?

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Exactly, [just as I said](https://stackoverflow.com/questions/24998447/displaying-database-with-php#comment38867225_24998447) ;-) – Funk Forty Niner Jul 28 '14 at 15:21
  • Cheers for the response. You're right while ($employee=mysql_fetch_assoc($records)){ should be while ($gig=mysql_fetch_assoc($records)){ – LewDawg Jul 28 '14 at 15:23