Want to use LIMIT but its not appropriate for my needs

Off Topic:

Dope! I’m a bit off today :lol:

It seems I’m having a little bit of a problem with the code below which is working in that the correct country names return and in also the way i want them to as in the hotels using LIMIT.

This is what I got so far:


$r=mysql_query("SELECT DISTINCT Nom_Cntry FROM tbl_countries c JOIN (SELECT IdCntry_Hot FROM tbl_hotels WHERE Act_Hot = '1' ORDER BY Id_Hot DESC LIMIT 0, 10) sq ON sq.IdCntry_Hot = c.Id_Cntry");
 
while($q=mysql_fetch_assoc($r)){ ?> 
<input type="checkbox" name="countries[]" value="<?=$q['Id_Cntry']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Cntry'], $_REQUEST['countries'])) ? "checked=\\"checked\\" " : "")?> class="inline" /><?=$q['Nom_Cntry']?>&nbsp;<?=$q['IdCntry_Hot']?>

What Im trying to do now is create the count, and the first thing I noticed was that although <?=$q[‘Nom_Cntry’]?>, <?=$q[‘IdCntry_Hot’]?> doesnt, so if a user selects one of the countries they all become checked.

http://devchecksafetyfirst.csf.dcmanaged.com/category_Result.php?Category=Latest Additions

Okay, so here is your problem:

There is no Id_Cntry or IdCntry_Hot returned from your query. Nom_Cntry is the only column being returned. Since this is MySQL, I think you can do this: SELECT Id_Cntry, IdCntry_Hot, DISTINCT Nom_Cntry … rest of query …

That would at least get you the columns you need for your while loop. You are seeing all checkboxes being checked because each of them have a value of “”, and since they all have the same value, when you check one, it checks them all.

We’ll need to get your query fixed to be able to get this operating correctly.

Right of course yes, will have a look now.

no, you can’t :slight_smile:

:smiley: Maybe when I wake up I’ll see the actual solution :slight_smile: Anyone else have kids that get you up at 4:30 in the morning because they don’t want to sleep anymore? Anyone?

LOL, thats mad…

Yes I got kids, but the game they play is during any school holidays its up at 6.30 - 7am, then when school starts we cant get them out of bed at 8, how does that work!

No worries cpradio

This is that whole section, I havent properly had a go at the count bit yet, as couldnt get the ID out as you know.


if ($selectCategory=="Latest Additions") {
	
$r=mysql_query("SELECT DISTINCT Nom_Cntry FROM tbl_countries c JOIN (SELECT IdCntry_Hot FROM tbl_hotels WHERE Act_Hot = '1' ORDER BY Id_Hot DESC LIMIT 0, 10) sq ON sq.IdCntry_Hot = c.Id_Cntry");

while($q=mysql_fetch_assoc($r)){ ?>
<input type="checkbox" name="countries[]" value="<?=$q['Id_Cntry']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Cntry'], $_REQUEST['countries'])) ? "checked=\\"checked\\" " : "")?> class="inline" /><?=$q['Nom_Cntry']?>&nbsp;<?=$q['IdCntry_Hot']?><?
$query1 = mysql_query("select count(Id_Hot) as total1 FROM tbl_hotels WHERE (IdCntry_Hot=". $q['Id_Cntry'] .")");
$result1 = mysql_fetch_array($query1);
?>
<span class="result_Number_Count">[<? echo $result1['total1'];?>]</span>
<br/>
}

You should be able to do this:

SELECT DISTINCT Id_Cntry, Nom_Cntry

You don’t actually need to get IdCntry_Hot anyway, as it’s the same value as IdCntry

Off Topic:

Mine are ages 1 and 3, so no school yet, but I bet they start to sleep in when school does come around sigh

@fretburner ;, well spotted :smiley:

Yes great that worked, so I got the Id I needed now, see about the rest of it now.

Cheers

6 and 8 mine are so we just coming out of the baby part, so they sleeping better, but they still hard work, and yes I dont get the holiday thing…

very early when its holiday time, seemingly very tired during school time and cant get them up.

I got that id woring now thanks, so am going to test it to make sure I can select a country and also need to put the count to it.

Cheers

OK Im nearly there, I got a count working, but its counting too much, cant seem to keep it to the 10 limit.


<input type="checkbox" name="countries[]" value="<?=$q['Id_Cntry']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Cntry'], $_REQUEST['countries'])) ? "checked=\\"checked\\" " : "")?> class="inline" /><?=$q['Nom_Cntry']?>&nbsp;<?
$query1 = mysql_query("select count(Id_Hot) as total1 FROM tbl_hotels WHERE (IdCntry_Hot=". $q['Id_Cntry'] .") AND Act_Hot = '1' ORDER BY Id_Hot DESC LIMIT 0, 10");
$result1 = mysql_fetch_array($query1);

Tried this also with no results.


$query1 = mysql_query("select count(Id_Hot) as total1 FROM tbl_hotels WHERE (IdCntry_Hot=". $q['Id_Cntry'] .") AND Act_Hot = '1' c JOIN (SELECT IdCntry_Hot FROM tbl_hotels WHERE Act_Hot = '1' ORDER BY Id_Hot DESC LIMIT 0, 10) sq ON sq.IdCntry_Hot = ". $q['Id_Cntry'] ."");

Try this:

SELECT DISTINCT Id_Cntry, Nom_Cntry, COUNT(*) AS total1 FROM tbl_countries c JOIN (SELECT IdCntry_Hot FROM tbl_hotels WHERE Act_Hot = '1' ORDER BY Id_Hot DESC LIMIT 0, 10) sq ON sq.IdCntry_Hot = c.Id_Cntry GROUP BY Id_Cntry, Nom_Cntry

No didnt output anything cpradio, but shouldnt something in that = to an ID or something from the select query for the country, for example, but this didnt work either.


$query1 = mysql_query("select count(Id_Hot) as total1 FROM tbl_hotels WHERE Act_Hot = '1' c JOIN (SELECT IdCntry_Hot FROM tbl_hotels WHERE Act_Hot = '1' ORDER BY Id_Hot DESC LIMIT 0, 10) sq ON sq.IdCntry_Hot = ". $q['Id_Cntry'] ."");

p.s how do you get the code sql to show correctly in the posts, im using [sql] [/sql] and its not right

[noparse]


[/noparse]

I took a different approach, so instead of two queries, you have 1.

if ($selectCategory=="Latest Additions") {
	
$r=mysql_query("SELECT DISTINCT Id_Cntry, Nom_Cntry, COUNT(*) AS total1 FROM tbl_countries c JOIN (SELECT IdCntry_Hot FROM tbl_hotels WHERE Act_Hot = '1' ORDER BY Id_Hot DESC LIMIT 0, 10) sq ON sq.IdCntry_Hot = c.Id_Cntry GROUP BY Id_Cntry, Nom_Cntry");
 
while($q=mysql_fetch_assoc($r)){ ?> 
<input type="checkbox" name="countries[]" value="<?=$q['Id_Cntry']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Cntry'], $_REQUEST['countries'])) ? "checked=\\"checked\\" " : "")?> class="inline" /><?=$q['Nom_Cntry']?>&nbsp;<?=$q['IdCntry_Hot']?>
<span class="result_Number_Count">[<? echo $q['total1'];?>]</span>
<br/>

Right I see, that works thank you cpradio, looking good.

now the DISTINCT is completely redundant :slight_smile:

Yes, yes it is… :lol: At least it doesn’t bomb… (or maybe it’d be nice if it did…)

SELECT Id_Cntry, IdCntry_Hot, Nom_Cntry from table “insign”… You can’t???