I can't seem to limit the result to a desired number. I have this code:

//GET THE TOTAL OF LEVEL 2
$result = mysql_query("SELECT COUNT(*) FROM agents WHERE (sponsor = '1' or sponsor =  '2' or sponsor = '3') LIMIT 0,1")or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {
$lvl2parent = $row['COUNT(*)'];
echo "<b>Total Level 2 </b> : ";
echo "$lvl2parent <br><br>";

On the code above, the sponsors 1, 2, 3 has 2 records each. And as I see it, the LIMIT 0,1 applies to each instead of giving me ONLY 1 RESULT from the overall. I thought of using an array to echo all results and then choose 1 from that but I am not too familiar with it.

Hope you can help me. this is the final function to finish my project. Thanks!

The LIMIT always applies to the end result of the query. Even without the limit, the count(*) will only return 1 result row.

I'm not sure of what you try to achieve. If you want the count per sponsor, then you could try a union:

SELECT COUNT(*) FROM agents WHERE sponsor = '1'
UNION
SELECT COUNT(*) FROM agents WHERE sponsor = '2'
UNION
SELECT COUNT(*) FROM agents WHERE sponsor = '3'

Thanks for the reply. Anyway, I would like to retrieve all the downlines of the sponsors 1 - 3 but I need to choose a specific number of result from ALL those results NOT from each sponsor's result.

Example: 1 - 3 sponsors has 2 results in each so that would result to 6 members all in all. Now, I would like to get only 1 member from the 6 members.

I hope that would clear it. i am not so familiar. with this. thak you so much!

The LIMIT always applies to the end result of the query. Even without the limit, the count(*) will only return 1 result row.

I'm not sure of what you try to achieve. If you want the count per sponsor, then you could try a union:

SELECT COUNT(*) FROM agents WHERE sponsor = '1'
UNION
SELECT COUNT(*) FROM agents WHERE sponsor = '2'
UNION
SELECT COUNT(*) FROM agents WHERE sponsor = '3'

Then you could use this one:

SELECT * FROM agents WHERE (sponsor = '1' or sponsor =  '2' or sponsor = '3') LIMIT 1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.