我想获取表中给定引荐ID的总用户数

hi i want to fetch the total user count of given referral ids in table i have tried using left join but i am getting duplicate results from mysql.

i am attaching of screenshot of my table.
when user register we ask the sponser id which is actually the referral id 
of other user.

table containing the referral id and sponser id

In php manual, describe the function imagejpeg( resource $image [, string $filename [, int $quality ]] )

imagejpeg() creates a JPEG file from the given image

An image resource, returned by one of the image creation functions, such as

imagecreatetruecolor()

or

resource imagecreatefromjpeg ( string $filename )

then you can use imagejpeg to output an image

Change the JS to:

function post(form)
 { loading(1); 
   $.ajax({ type: 'POST',
            dataType: 'image/jpeg',
            url: 'collage.php',
            data: $('#'+form).serialize(), 
            success: function(data) 
      { $('#image').html('<img src="data:'+base64_encode(data)+'"') }
           });
   return false; }

See This question for information about implementing base64_encode in JS.

I don't see why you need ajax anyway. collage.php returns a valid image, so you can use the link used for your ajax call as the img tag src url. Just pass any variables you may need through the query string.

Example:

var queryString = $('#' + form).serialize();
$('#image').html('<img src="collage.php?' + queryString  + '"/>');