When retrieving data from a table, I assign it to an array of values ​​of the form $ page_vars ['column_name_in_BD']:

... $result = $stmt->fetch( PDO::FETCH_ASSOC ); $stmt->closeCursor(); if( $stmt->rowCount() ) { foreach( $result as $key => $value) { $page_vars[$key] = $value[$key]; } } else { return 404; } 

I noticed that it occurs when an empty record is in the database (the 'author' field is of type varchar (255), since this table contains all the pages of the site, for some pages there is no author). It seems to work on the site does not affect, but from the principle I want to remove this warning! Well now, actually, the question is: how to get rid of this warning more elegantly, preferably without crutches of the type for each page without an author, to introduce a default like no_author? Well, error_reporting () does not offer :)

  • @Fike, thanks! Transform in response comments, accept! I rewrote the code from while in foreach and forgot to delete this $ key. And almost crutches were not made :) I hate PCP! :)) - MDJHD
  • @MDJHD done - etki

1 answer 1

@MDJHD

 foreach( $result as $key => $value) { $page_vars[$key] = $value[$key]; } 

alarm-alarm, you get $ key from $ result, and you dig with it in $ value, is that exactly what was meant? Maybe there generally $ key is not needed?