Jump to content

Checking returned results in a while loop


Nieeru

Recommended Posts

Hey there! Still very new to these forums. :)

 

I'm creating a script that reads an external XML file, populating a database and then returning results.

 

I know that I can just read the XML file, loop it through foreach with pre-defined variables outside and then preform the checks, like this:

$var1 = true; $var2 = true;
foreach($xml->info->members as $member)
{
if(empty($member['classId'] == 1)) { $var1 = false; }
elseif(empty($member['classId'] == 2)) { $var2 = false; }
}

if(!$var1)
{
// Do something if it's FALSE
} else {
// Do something if it's TRUE
}

...

 

However, I tried using this logic with MySQL, selecting everything in the database as it only stores the information I need, then checking the query, for so to continue parsing it.

I tried using

if(empty($data['classId'] == 1)) { $var1 = FALSE; }

but it just returns an error while

if(mysql_num_rows($data['classId'] == 1) < 1) { $var1 = FALSE; }

always returns false, even if the field classId is populated by one or more members.

 

Without having to create seperate queries for every occurance of classId (which for the record are 10 different ID's), I don't really know how to solve this issue.

 

Basically, what I want to do is, select everything from a database, define variables for every class ID as true by default, then loop the returned mysql results and if there are no members within one or more classId's define them as false.

 

I'm not really sure how to work out the logic behind it.

 

I'd really appreciate some help with this. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.