How to call php function on page in wordpress?

I want to call php function that pulls data from database in WordPress and show results
on page for example.
My function/query is like following way:

<?php
     global $wpdb; 
     $myrows=$wpdb->get_results("SELECT ident_broj, ime, prezime FROM marija_radnik_CYR");
     echo $myrows;
?>

Related posts

Leave a Reply

2 comments

  1.  global $wpdb;
    
        $results = $wpdb->get_results("SELECT ident_broj, ime, prezime FROM marija_radnik_CYR"); 
       if(!empty($results)) {// do anything }
    

    declare wpdb global first and then use it !

  2.    $myrows = $wpdb->get_results( "SELECT ident_broj, ime, prezime FROM marija_radnik_CYR" );
       echo $myrows;
    

    Do not require to declare $wpdb again if your using the function in already relative wp page