Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-28-2012, 02:02 AM   PM User | #1
ycpc55
New Coder

 
Join Date: Jan 2007
Posts: 42
Thanks: 4
Thanked 0 Times in 0 Posts
ycpc55 is an unknown quantity at this point
Help with $row

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.
PHP Code:
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

ycpc55 is offline   Reply With Quote
Old 07-28-2012, 02:07 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
PHP Code:

foreach(mysql_fetch_array($result) as $row){

if (
$row["actnum"] == "0"){ 
//Code here 

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

}
// end foreach 
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
ycpc55 (07-28-2012)
Old 07-28-2012, 04:42 AM   PM User | #3
ycpc55
New Coder

 
Join Date: Jan 2007
Posts: 42
Thanks: 4
Thanked 0 Times in 0 Posts
ycpc55 is an unknown quantity at this point
Again thanks mlseim

Also, anyone know if this is wise to do? thanks..
PHP Code:
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 

ycpc55 is offline   Reply With Quote
Old 07-28-2012, 05:07 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
ycpc55 (07-28-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:33 AM.


Advertisement
Log in to turn off these ads.