Jump to content


Photo

Please help me with my code check it out


  • Please log in to reply
4 replies to this topic

#1 theoretical_dreamer

theoretical_dreamer
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 May 2006 - 02:20 AM

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 May 2006 - 02:24 AM

[!--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']
Legend has it that reading the manual never killed anyone.
My site

#3 theoretical_dreamer

theoretical_dreamer
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 May 2006 - 02:31 AM

but if you print their values their equal right?
Output:
The value of ctr is 32
IP4: 32


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 May 2006 - 02:48 AM

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?"
$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>";
}

Legend has it that reading the manual never killed anyone.
My site

#5 theoretical_dreamer

theoretical_dreamer
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 May 2006 - 03:08 AM

I try to use var_dump() function and it seems the two variables are different types ($ctr is int and $info4['IP4'] is string) how can I convert a string to an int? or vice-versa




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users