0

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

Narendra Sharma
  • 29
  • 1
  • 3
  • 10

3 Answers3

3

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  + '"/>');
iMoses
  • 4,338
  • 1
  • 24
  • 39
  • thanks your answers worked like charm..but i am sending array of images to collage.php.. it didn't work at all .but it works for two or one images instead ! – Narendra Sharma Nov 07 '12 at 09:43
  • Can you explain? Are you using `collage.php` several time on the same page or is it that `collage.php` returns more than one image? – iMoses Nov 07 '12 at 09:46
  • This is the code i am sending to collage.php which takes all images and creates collage.. $photo[source] contains address of images in foreach loop.. – Narendra Sharma Nov 07 '12 at 09:55
  • When returning an image via `Imagejpeg` you can only return **one** image. In your specific case I'd suggest you take the photo sources into an js array and create `img` tags passing each `src` a source for a different photo as a queryString. Change `collage.php` into a method which only takes one photo at a time. – iMoses Nov 07 '12 at 10:05
  • Another idea is to save the images to your server (if at all possible) and then returning a json containing a list of the new photos urls. You might wanna make sure you don't recreate an already saved image, depends on your demands. – iMoses Nov 07 '12 at 10:07
  • nope.. my collage.php script takes an array of images i have tested it multiple times.. my question is can your querystring can serialise an array of images in am array like.. like .so can it take collage[] and serialize it – Narendra Sharma Nov 07 '12 at 10:11
  • Does `collage.php` returns a `header('Content-Type: image/jpeg');`? Because if so then it doesn't make sense of me. I may need some more code to understand what you're doing or you could try and explain to me what does `collage.php` returns. – iMoses Nov 07 '12 at 10:16
  • header('Content-Type: image/jpeg'); it returns valid image – Narendra Sharma Nov 07 '12 at 10:20
  • Ok, I may seem to understand my confusion. Do you take multiple sources and create a collage, a single image containing them? It sounds like your problems are on the server-side, so basically this answers your question. If you need more advice with your code may I suggest opening a new question, posting the relevant code there? Because I can't really help you when I have no idea what your code does. – iMoses Nov 07 '12 at 10:22
1

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.

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks. I moved the base64 encoding into the JS. – Barmar Nov 07 '12 at 08:24
  • That is a nice solution, yet I still see no reason for implementing `base64_encode` in this specific case. Also, IE8- has a 32KB limitation on using base64 urls. You have to take it into consideration in case your image might be as big or even bigger. – iMoses Nov 07 '12 at 08:28
  • I have to send an array of images to collage.php ..your code doesn't seem to be good to me.. – Narendra Sharma Nov 07 '12 at 10:06
  • I didn't change anything regarding what you're sending to collage.php, just how you display what it returns. If you want to put the image data directly in an `` tag, you have to use the `data:` prefix followed by a base64 encoding of the data. Normally the `src` attribute contains the URL to get the data from, which is iMoses solution. – Barmar Nov 07 '12 at 17:02
0

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

tinybai
  • 916
  • 1
  • 6
  • 17