1

I added a table in the database which collects names through a form. I want to output the latest entered name on a different page than the one which contains the form.

In order to print the data I added the following php code through a WPcode shortcake. The used code is:

global $wpdb;
$result = $wpdb->get_results( 'besuchername FROM besucher');
{
echo $result;
}

However, the only output I get is: Array

Please advise. Thank you.

5
  • Loop thru the results array. See developer.wordpress.org/reference/classes/wpdb/#examples-5
    – shanebp
    Jul 30 at 14:39
  • echo cannot print complex data types. Use var_dump() or print_r() to print out an array for debugging purposes.
    – bosco
    Jul 30 at 16:15
  • I tried but still got array... global $wpdb; $result = $wpdb->get_var( 'SELECT besuchername FROM besucher ORDER BY id DESC LIMIT 1'); { print_r('$result') ; }
    – Philipp
    Jul 31 at 11:39
  • ok. I made some progress :)
    – Philipp
    Jul 31 at 13:12
  • global $wpdb; $results = $wpdb->get_results( 'SELECT * FROM besucher LIMIT 1'); { foreach($results as $result) { echo $result->besuchername.'<br>'; } } ?> displays all names, but I only need to print the latest entry. How to do this?
    – Philipp
    Jul 31 at 13:12

0

Browse other questions tagged or ask your own question.