PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm simply trying to retrieve a max value from my database, and no matter what I do I get an undefined index error for the "navPosition" (line 14) regardless of if the query returns any results or not. Any ideas what might be causing this?
To expound on what onion said just a little, you need to provide an alias for your MAX(navPosition). So just switch your query to MAX(navPosition) as `navPosition` or something along those lines and it should work for you then.
Just a personal preference really, but aliasing things to existing column names is a bad idea in my opinion. When your code grows to the point where several people are required to maintain it and the SQL is separated from the PHP (eg stored procedures) it'll stop being obvious what 'navPosition' is ... is it the value from the column? Is it the MAX() value? Is it something else?
It's better to use a logical name that tells the developer exactly what is being returned - max_navPosition is much less ambiguous.