• Resolved 44nato44

    (@44nato44)


    I created a table tbl_Buildings for which I am not able to get the data from.

    When I run the top query alone, it works. But together or the second query alone it display nothing like there is a fault.

    I verified the table and field names of course 😉

    Hope you have an idea why it is not working.

    global $wpdb;
    $wpdb->show_errors(); 
    
    <p>From Database </p>
    
    $fivesdrafts = $wpdb->get_results(
    	"
    	SELECT ID, post_title
    	FROM $wpdb->posts"
    );
    
    foreach ( $fivesdrafts as $fivesdraft )
    {
    	echo $fivesdraft->post_title;
    }
    
    <p>From Civ TBG </p>
    
    $CivTBGs = $wpdb->get_results(
    	"
    	SELECT Building_ID
    	FROM $wpdb->tbl_Buildings"
    );
    
    foreach ( $CivTBGs $CivTBG)
    {
    	echo $CivTBG->Building_ID;
    }
    
    $wpdb->print_error();
    echo "Test";
Viewing 4 replies - 1 through 4 (of 4 total)
  • You have made a small syntax error, that may be the issue.

    foreach ( $CivTBGs as $CivTBG)

    Thread Starter 44nato44

    (@44nato44)

    Thanks but unfortunately it was not it.

    If you have another idea please let me know?

    Instead of :
    SELECT Building_ID FROM $wpdb->tbl_Buildings

    Can you try using :
    SELECT Building_ID FROM tbl_Buildings

    Also do a var_dump of the results to help debug

    Thread Starter 44nato44

    (@44nato44)

    Thanks everybody .. I got it resolved

    Thanks to ThemeSumo and I also noticed that I had not echoed

    <p>From Civ TBG </p> and <p>From Database </p> were missing both the echo “”

    I think I had been trying too many different things

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wpdb not working with custom table’ is closed to new replies.