Jump to content

Archived

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

theoretical_dreamer

Php Noob here need help

Recommended Posts

need help regarding syntax please check my code tnx

$rs4= mysql_query("SELECT IP4 FROM ipadd ORDER BY IP4")or die(mysql_error());
$info4 = (mysql_fetch_array( $rs4 ));
ctr=31;
if (ctr=.$info['IP4'].)
{
print "The available IP is:".$info4['IP4'].;
}
else
{
Print "<b>IP4:</b> ".$info4['IP4']. " <br>";
while($info4 = mysql_fetch_array( $rs4 ))
{

while (ctr==.$info4['IP4'].)
{
ctr++;
if (ctr!=.$info4['IP4'].)
{
print "It works";
}
}

Print "<b>IP4:</b> ".$info4['IP4'] . " <br>";
}
}

Share this post


Link to post
Share on other sites
Don't forget to tell us what errors you get and identify the lines in your code. php provides really useful error messages that (with a little practice) lead you to the trouble spots.

Most of your problems stem from mis-use of the . concatenation operator (which is used exclusively for adding strings to make longer strings. Note also the equality check operator is ==. So, for example:
[code]if (ctr=.$info['IP4'].)
{
print "The available IP is:".$info4['IP4'].;[/code]
Should be:
[code]if (ctr==$info['IP4'])
{
print "The available IP is: ".$info4['IP4'];[/code]

Share this post


Link to post
Share on other sites
Your souce is filled with syntax errors. For starters:[list][*]The comparision operator for equality is the double equal "==" not the single equal "="[*]The period is the string concatenation operator, code like [code]<?php if (ctr=.$info['IP4'].) ?>[/code] is completely meaningless. What were you trying to write?[/list]Your code written syntactally correct would look something like this: (whether it's logically correct is another question)
[code]<?php
$rs4= mysql_query("SELECT IP4 FROM ipadd ORDER BY IP4")or die(mysql_error());
$ctr=31; // need a $ infront of the variable and since it doesn't change, move it out of the loop
while ($info4 = mysql_fetch_assoc( $rs4 )) { // make this a "while" loop
    if (ctr == $info['IP4'])
       print "The available IP is:".$info4['IP4'];
    else
       print "<b>IP4:</b> ".$info4['IP4']. " <br>";
    while ($ctr == $info4['IP4'])
    {
         $ctr++;
         if ($ctr != $info4['IP4'])
             print "It works";
    }
    Print "<b>IP4:</b> ".$info4['IP4'] . " <br>";
}
?>[/code]

Ken

Share this post


Link to post
Share on other sites
guys i did wat u said but it still didn't work here's my edited code

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

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

while($info4 = mysql_fetch_array( $rs4 ))

{

while ($ctr=.$info4['IP4'].)
{
$ctr++;
if ($ctr!=.$info4['IP4'].)
{
print "It works";
}
}

Print "<b>IP4:</b> ".$info4['IP4'] . " <br>";
}
}

Share this post


Link to post
Share on other sites
No, No, No. You didn't do what we said. You didn't post what the errors were. You didn't identify which lines the errors occurred at.

Change this:
[code]if ($ctr=.$info['IP4'].) //if ctr is equal to the 1st value of IP4 field in the database
{
print "The available IP is:".$info4['IP4'].;[/code]
To this (again, carefully please) and try again.
[code]if ($ctr==$info['IP4']); //if ctr is equal to the 1st value of IP4 field in the database
{
print "The available IP is: ".$info4['IP4'];[/code]

Share this post


Link to post
Share on other sites

×

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.