WordPress.org

Ready to get started?Download WordPress

Forums

Using MySQL with INNER JOIN in WP (1 post)

  1. phillbooth
    Member
    Posted 3 years ago #

    Hi, I am trying to do a query to a custom table using "Inner Join" but some some reason I cant seem to do it through the wordpress db connection, any idea why?

    Code that FAILS...

    global $wpdb;
    
    		if( !function_exists('get_option') )
    		{
    			require_once('wp-config.php');
    		}
    
    $result = $wpdb->get_results("SELECT t1.*, t2.coId, t2.coName FROM mytable1 AS t1 INNER JOIN mytable2 AS t2 ON t1.qsCoId = t2.coId WHERE t1.authorised='0' ORDER BY t1.qsDateAdded DESC");
    
    while($row=mysql_fetch_array($result))
    {
    $row["qsCoId"];
    }

    but this code DOES work...

    mysql_connect ("localhost", "mydb", "mypasswordn");
    @mysql_select_db("web102-csnbench") or die( "Unable to select database");
    
    $result = mysql_query("SELECT t1.*, t2.coId, t2.coName FROM mytable1 AS t1 INNER JOIN mytable12 AS t2 ON t1.qsCoId = t2.coId WHERE t1.authorised='0' ORDER BY t1.qsDateAdded DESC");
    
    while($row=mysql_fetch_array($result))
    {
    $row["qsCoId"];
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags