WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_row associative array not working (3 posts)

  1. cbonwp
    Member
    Posted 7 months ago #

    can anyone spare a minute to solve this as i'm going spare?
    I call this function from within a template file. The db table is set up correctly but after the get_row the associative array $record fields ID and nrecords return the debug notice "undefined index" and field pflag contains 2 instead of 1.
    thanks in advance

    function x( $dbstring, $user_id )
    
    {
    	global $wpdb;
    	global $table_prefix;
    
    	$tablename = $table_prefix . $dbstring;
    	$admin = ADMINRECORD;
    
    	$record = $wpdb->get_row("SELECT * FROM $tablename WHERE ID = '$admin'", ARRAY_A);
    
    	if(( $record = false ) OR ( $record = null ))
    	{
    		return 'dberror';}
    
    	if( $record['pflag'] = ITEMISFREE )
    	{
    		$msg = 'db = ' . $tablename . ' user = ' . $user_id . ' admin record free item contents = ';
    		$msg = $msg . $record['ID'] . ',' . $record['nrecords'] . ',' . $record['pflag'];
    		return $msg;}
    
    	return 'ok';
    }

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

  2. ianhaycox
    Member
    Posted 7 months ago #

    Use == to test for equality not =

    if(( $record = false ) OR ( $record = null ))

    should be

    if(( $record == false ) OR ( $record == null ))

    otherwise your setting $record and trashing the results from get_row

    Same forthe if() below.

  3. cbonwp
    Member
    Posted 7 months ago #

    ah, thanks - the joys of a different language!

    in the meantime i gave up on the wp functions and went direct to the db using mysqli queries while making the same mistake. Interestingly, sometimes i got the right data.
    I've reverted to the wp functions and it now works.
    thanks, clive

Reply

You must log in to post.

About this Topic