Jump to content

Please help me with my code check it out


Recommended Posts

Just want to ask y there is no output in the If condition:

<?
include("conf/config.php");
$link = mysql_connect($database['host'],$database['username'],$database['password']);
mysql_select_db($database['name'],$link);

$rs4 = mysql_query("SELECT IP4 FROM ipadd ORDER BY IP4")or die(mysql_error());
$info4 = (mysql_fetch_array( $rs4 ));
$ctr=31;

if ($ctr != 31) {//if ctr is equal to the 1st value of IP4 field in the database
Print "<b>The IP is available:</b> ".$info4['IP4']. " <br>";
}

else
{
//Print "<b>IP4:</b> ".$info4['IP4']. " <br>";
$ctr++;
Print "The value of ctr is ";
Print $ctr; //value of ctr is 32
while($info4 = mysql_fetch_array( $rs4 ))

{
$ctr++;
Print "<br> <b>IP4:</b> ".$info4['IP4']. " <br>";
Print "The value of ctr is ";
Print $ctr;

if ($ctr==$info4['IP4'])
{
print "It is equal "; //Doesn't output at all
print $ctr;
}

/*
else
{
print "Finally, its not";
$ctr;
}
*/
}
}
?>

Output:
The value of ctr is 32
IP4: 32
The value of ctr is 33
IP4: 33
The value of ctr is 34
IP4: 34
The value of ctr is 35
IP4: 35
The value of ctr is 36
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Just want to ask y there is no output in the If condition:[/quote]

Logically because $ctr is never equal to $info4['IP4']
Link to comment
Share on other sites

Well, logically they can't be the same. Best guess is that the thing from the database has some whitespace e.g. it's really "32 " not "32".

A better question might have been "how come this never generates any output?"
[code]$ctr=31;

if ($ctr != 31) {//if ctr is equal to the 1st value of IP4 field in the database
Print "<b>The IP is available:</b> ".$info4['IP4']. " <br>";
} [/code]
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.