• Resolved cbonwp

    (@cbonwp)


    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.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    Thread Starter cbonwp

    (@cbonwp)

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_row associative array not working’ is closed to new replies.