Jump to content

Loop question


karimali831

Recommended Posts

Hi,

 

Got a prob.

 

$getteams=safe_query("SELECT clanID, userID FROM ".PREFIX."cup_clan_members WHERE userID='$userID'");
while($te=mysql_fetch_array($getteams)) { 

 

I echo clanID in $getteams query above:

 

echo '<br>clanID = '.$te['clanID'].'';

 

Output:

 

clanID = 11

clanID = 35

clanID = 37

 

= is correct.

Now I want to use $te['clanID'] in $registered query below:

 

$registered=safe_query("SELECT * FROM ".PREFIX."cup_clans WHERE clanID='".$te['clanID']."' && 1on1='0' && cupID='$cupID'");

 

if(!mysql_num_rows($registered)) { echo 'no rows'; }else{ echo 'is rows'; }

 

Output:

 

clanID = 11no rows

clanID = 35is rows

clanID = 37no rows

 

== is correct

 

Problem:

 

If I used if(!mysql_num_rows($registered)) { die('die'); } it will die but there is rows for clanID 35? (above)

 

Don't know much about how loops work but if I changed the query from

clanID='".$te['clanID']."' to clanID='35' it'll work fine.

 

So I don't want it to die if there is rows for any clanID in the loop if that makes sense?

From the looks of it, it will die if a single clanID has no rows.

 

Hope you understand and thanks for help.

 

 

Link to comment
Share on other sites

foreach ($team_ids as $team_id) {
$registered = ...;
  if (mysql_num_rows($registered)) $is_registered_on_at_least_one_team = true;
}
if  (empty($is_registered_on_at_least_one_team)) die('a horrible death'); //jk

Link to comment
Share on other sites

$getteams=safe_query("SELECT clanID, userID FROM ".PREFIX."cup_clan_members WHERE userID='$userID'");

while($te=mysql_fetch_array($getteams)) {

  $registered=safe_query("SELECT * FROM ".PREFIX."cup_clans WHERE clanID='".$te['clanID']."' && 1on1='0' && cupID='$cupID'");

  if (mysql_num_rows($registered)) $is_registered_on_at_least_one_team = true;

}

if (empty($is_registered_on_at_least_one_team)) die('error message');

Link to comment
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.