0

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!

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by pritaeas
0

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'
0

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'
0

Then you could use this one:

SELECT * FROM agents WHERE (sponsor = '1' or sponsor =  '2' or sponsor = '3') LIMIT 1
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.