Undefined Index

I am getting the Undefined index error message but I dont know why. I need to know whats going on and why this is happening…I am trying to display records stored in MySQL…Here is a sample of my code…

<table>
<tr>
<th>Team Name</th>
<th>HomeTown</th>
<th>Wins</th>
<th>Losses</th>
<th>Ties</th>
<th>Division</th>

&lt;/tr&gt;

&lt;?php foreach($teams as $team): ?&gt;

&lt;tr&gt;
	&lt;td&gt;&lt;?php echo $teams['0']['Team Name']; ?&gt;&lt;/td&gt;
	&lt;td&gt;&lt;?php echo $teams['1']['HomeTown']; ?&gt;&lt;/td&gt;
	&lt;td&gt;&lt;?php echo $teams['2']['Wins']; ?&gt;&lt;/td&gt;
	&lt;td&gt;&lt;?php echo $teams['3']['Losses']; ?&gt;&lt;/td&gt;
	&lt;td&gt;&lt;?php echo $teams['4']['Ties']; ?&gt;&lt;/td&gt;
	&lt;td&gt;&lt;?php echo $teams['5']['Division']; ?&gt;&lt;/td&gt;

	print_r($teams)

What is going on here? Any feedback would be much appreciated!

Can you paste your mysql query and table structure?

SELECT Team.Teamid, Team Name, Team.Hometown, Team.Wins, Team.Losses, Team.Ties, Team.Division FROM teams AS Team WHERE 1 = 1 …

Teamid Team Name Hometown Wins Losses Ties Division
1 Parkview Pirates Mexia 5 2 1 TBall
2 Groesbeck Tire Groesbeck 8 7 2 TBall
3 Marlin Bulldogs Marlin 2 8 0 TBall
4 Hyden’s Hustlers Teague 1 8 1 TBall
5 Rally Boys Riesel 6 4 3 TBall

Make sure your query is valid and records were returned from your query (SELECT). Also you need to store the values in an appropriated array.

See this page for more info:
http://us2.php.net/manual/en/function.mysql-query.php

SELECT Team.Teamid, Team Name, Team.Hometown, Team.Wins, Team.Losses, Team.Ties, Team.Division FROM teams AS Team WHERE 1 = 1 …

Team Name doesnt have Team`. in front of it and all the rest do, that could be your issue.

Just check your query that is where the problem lies.

Just guessing as there is not much data to debug.

shouldn’t <?php echo $teams[‘0’][‘Team Name’]; ?
be
<?php echo $team[‘0’][‘Team Name’]; ?

“team” rather than “teams”

It should be and if still error then do a print_r($team) and see if it maths that structure you are using; team[0][column]

I don’t know what is going on here. I have tried just about everything people have suggest today! Lets start from the beginning. What does the undefined index error imply?

So, you chamged terms to term?
And what is the output of print_r($term)?

You have to provide more info. And you can google that error.

well actually I chnaged a few things! Im not getting the error mesage anymore…its just that my records appear above my columns! I dont know where i went south! I need to figure out what is causing my records to appear above my columns!

We will need to see your code for that but I think that issue is not HTML related. You are missing a tag somewhere

<table>
<tr>
<th>Team Name</th>
<th>Hometown</th>
<th>Wins</th>
<th>Losses</th>
<th>Ties</th>
<th>Division</th>

&lt;/tr&gt;


&lt;?php foreach($teams as $Team): ?&gt;

{
	&lt;?php echo $Team['Team'] ['Teamid']; ?&gt;
	&lt;?php echo $Team['Team'] ['Team Name']; ?&gt;
	&lt;?php echo $Team['Team'] ['Hometown']; ?&gt;
	&lt;?php echo $Team['Team'] ['Wins']; ?&gt;
	&lt;?php echo $Team['Team'] ['Losses']; ?&gt;
	&lt;?php echo $Team['Team'] ['Ties']; ?&gt;
	&lt;?php echo $Team['Team'] ['Division']; ?&gt;
}



	



&lt;?php endforeach; ?&gt;

There should <tr> after foreach starts and </tr> before foreach ends. That’s just malformed HTML issue. And ofcourse you need to close table after foreach

thanks rana…that did help! It had my tr tags earlier but between all my editing I deleted my tags! Now after I put my tags in the proper place…my records are still on top of my columns…I dont understand why my records arent under my columns.

You need to add the appropriate <tr>, </tr>, <td> and </td>s. Without those, it will indeed just put the content above the table.
Also, it’s either

foreach ($a as $b): ... endforeach;` or 
```php
foreach($a as $b) { ... }`, not both at the same time ;) 


```php

<table>
<thead>
  <tr>
    <th>Team Name</th>
    <th>Hometown</th>	
    <th>Wins</th>
    <th>Losses</th>
    <th>Ties</th>
    <th>Division</th> 
  </tr>
</thead>

<tbody>
  <?php foreach($teams as $Team): ?>
    <tr>
      <td><?php echo $Team['Team'] ['Teamid']; ?></td>
      <td><?php echo $Team['Team'] ['Team Name']; ?></td>
      <td><?php echo $Team['Team'] ['Hometown']; ?></td>
      <td><?php echo $Team['Team'] ['Wins']; ?></td>
      <td><?php echo $Team['Team'] ['Losses']; ?></td>
      <td><?php echo $Team['Team'] ['Ties']; ?></td>
      <td><?php echo $Team['Team'] ['Division']; ?></td>
    </tr>
  <?php endforeach; ?>
</tbody>
</table>

Just confirm, you also wrapped EACH row with “td” tags, right? It has to be, to be considered part of that table and row.

Rana you are swell!! I don’t know if you’re a male or female…but if u a dude “HIGH FIVE”!!..AND if you a woman…I swear I would kiss your feet right now!! Thanks!!