Click here to Skip to main content
15,886,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am trying to create a table dynamically. It works but I have an error:
Notice: Undefined index: in C:\xampp\htdocs\asset-management\reports\querys\by-status.php on line 20

Then here is the code I have written:
PHP
$query = "SELECT ".$columns." Item FROM tblitem WHERE Status=".$_POST['status'];
$result = mysql_query($query);

$tblCol = explode(",", $columns);

echo "<table>";

echo "<th>Item</th>";
foreach ($tblCol as $ColName){
	echo "<th>".$ColName."</th>";
}
while($row = mysql_fetch_array($result)){
	echo "<tr>";
	echo "<td>". $row['Item'] ."</td>";
	foreach ($tblCol as $columnName){
		echo "<td>". $row[$columnName] ."</td>";
	}
	echo "</tr>";
}

echo "</table>";

Can some one help me? It works fine but the error does not disappear.
Posted
Comments
enhzflep 4-Mar-15 4:16am    
You need to look at line 20 of your code. The error message typically means that you're trying to access an element in an array, using a key that doesn't exist.
For instance, if your sql table has a column named 'item' and you try to access an element of the $result array with 'Item', you'd get the same message.

Calling var_dump($result) would list the contents of the array, complete with the strings you could use to index any of the elements. You should try using var_dump as the first line of your while loop.

Failing that, edit your question to include

(1) the line in question (line 20)
(2) the names of the columns in your table (with the same capitalization as the DB has)

1 solution

Thank you for the comment. Finally found the answer ro my problem. I have this array([0]=>Status[1]=>) then when I call the array the blank one is added also which returns the error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900