• Hello All, First post so be gentle πŸ™‚

    Im trying to do some simple database display code with php, and to begin im simply trying to select any data and display the array as a test but cant even do that.

    so far I have tied plugins php snippets, insert php code snippet, php code widget.

    i can echo etc as test but cant call any data.
    (my table has no prefix it was imported to wordpress db manually.

    initially trying :

    $fetch = mysql_query("SELECT * FROM maindata") or die("selecting failed");
    $array = mysql_fetch_array($fetch);
    echo "<pre>";
    print_r($array);
    echo "</pre>";

    then after googling for help tried:

    global $wpdb;
    $result = $wpdb->get_results( "SELECT * FROM maindata" );
    $array = mysql_fetch_array($result);
    echo "$array";

    then exporting data to separate database and using a new connection:

    global $wpdb;
    $user="newuser";
    $pass="newpass";
    $db="newdb";
    
    $link = mysql_connect("localhost", $user, $pass);
    	if (! @link) {
    			die ("coudnt connect");
    		}
    	mysql_select_db("$db")
    		or die ("selecting failed");
    
    $result = $wpdb->get_results( "SELECT * FROM maindata" );
    $array = mysql_fetch_array($result);
    echo "$array";

    the strange thing is im not getting “selecting failed’ errors, just no data.
    crazy is on the approach so im hoping someone can get me over this hurdle before i reach quiet boil.

    thanks in advance.
    steve
    WordPress 4.2.2 running MH Magazine theme.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘simple database call not working’ is closed to new replies.