Jump to content

Recommended Posts

I am trying to set up a loop that goes up to 10 and changes the query so instead of

 


$male1mQ=mysql_query("select gender, level from athletes where gender='1' and level='1' ");
$male1=mysql_num_rows($male1Q);

$male2mQ=mysql_query("select gender, level from athletes where gender='2' and level='2' ");
$male2=mysql_num_rows($male2Q);

 

over and over up to 10 ... I am trying to put this in a loop and I'm stuck.

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/176962-loop/
Share on other sites

$Number = "1";
while ($Number!="11") {
   $MaleMQ['$Number']=mysql_query("select gender, level from athletes where gender='$Number' and level='$Number' ");
   $Male['$Number']=mysql_num_rows($MaleMQ['$Number']);
   $Number = $Number + "1";
}

Possibly, I couldn't think of another solution for the query variable names, but there is probably one out there. Hope this helps :)

 

~Glenugie~

Link to comment
https://forums.phpfreaks.com/topic/176962-loop/#findComment-933047
Share on other sites

Why don't you just use a single query with BETWEEN and if you need the number of rows for the values 1-10 you can just use COUNT and GROUP BY level or gender.

 

That sounds like it will work...I didn't think of it thank you.

 

I haven't used that type of query before though.

 

I understand BETWEEN, COUNT, and GROUP but puting them together hurts my brain :)

 

Do you have an example I can look at?

Link to comment
https://forums.phpfreaks.com/topic/176962-loop/#findComment-933054
Share on other sites

Why does this get stuck?

 

$level = 1;

while ($level <= 10)
{

// if I "echo $level" it counts to 10???

$maleQ.$level=mysql_query("select gender, level from athletes where gender='$level' and level='$level' ");

$male.$level=mysql_num_rows($maleQ.$level);

$level++;

}

Link to comment
https://forums.phpfreaks.com/topic/176962-loop/#findComment-933059
Share on other sites

Hi

 

Suspect these 2 lines are corrupting $level when you assign to $maleQ.$level / $male.$level.

 

$maleQ.$level=mysql_query("select gender, level from athletes where gender='$level' and level='$level' ");

$male.$level=mysql_num_rows($maleQ.$level);

 

I presume you are trying to assign to a variable called $male1 / $male2 / etc. If so it would be far easier to use arrays.

 

That said it would be FAR easier to use Maqs suggestion of a single query using between.

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/176962-loop/#findComment-933078
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.