...

View Full Version : Help with $row



ycpc55
07-28-2012, 03:02 AM
Hi,
here i am again asking for help lol. In my code i have 3 lines as shown below, i am almost sure i shouldn't have it the way it is. So my question is what is the right way of doing this? sorry guys for all the questions, as you can see i'm still learning. thanks.

if ($row = mysql_fetch_array($result)){
if ($row["actnum"] == "0"){
if ($row["numloginfail"] <= 5){

Should it be like this?
if ($row = mysql_fetch_array($result)){
}
if ($row["actnum"] == "0"){
//Code here
}
if ($row["numloginfail"] <= 5){
//Code here
}

mlseim
07-28-2012, 03:07 AM
foreach(mysql_fetch_array($result) as $row){

if ($row["actnum"] == "0"){
//Code here
}
if ($row["numloginfail"] <= 5){
//Code here
}

}// end foreach

ycpc55
07-28-2012, 05:42 AM
Again thanks mlseim

Also, anyone know if this is wise to do? thanks..


From this:
if ($row["actnum"] == "0"){
//Code here
}
if ($row["numloginfail"] <= 5){
//Code here
}
To this:
if ($row["actnum"] == "0" || $row["numloginfail"] <= 5){
//Code here
}

Fou-Lu
07-28-2012, 06:07 AM
That depends on what //code here represents.
The difference is that the first block allows 2x possible modifications on the branch conditions, while the second block allows only 1x. So it depends on if it makes sense to perform an action based on actnum and numloginfail separately, or only if it makes sense to perform an operation if either match.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum