Jump to content

nachotico

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by nachotico

  1. Just to help some fulks who don't know that and helping to grow the community <?php $host="localhost"; $username="user"; $password="mysql_password"; $database="database_name"; $table="table_name"; $connection = mysql_connect("$host", "$username", "$password") or die ("Unable to connect to server"); mysql_select_db("$database") or die ("Unable to select database"); $sql = "TRUNCATE TABLE `$table`"; mysql_query($sql); echo "Table Deleted"; mysql_close($connection); ?> have a nice day...
  2. hi i'm new using PHP here is what i need> i have a MySQL database that contain Decimal IPs -- the issue is that i don't know how to after extract them convert them to a real IP. here is what i have for the moment> <? $print_ip = dec2ip($row[ip1]); // where the ip should go into a table echo "<td> $print_ip </td>"; /// here is the function decimal to ip function dec2ip($dec) { if($dec>0) { $dec=(double) 4294967296+$dec; } if($dec>16777215) { $ip=$dec-(intval($dec/256)*256); $dec=(double) intval($dec/256); } else $ip="0"; if($dec>65535) { $ip=($dec-(intval($dec/256)*256)).".".$ip; $dec=(double) intval($dec/256); } else $ip="0.".$ip; if($dec<255) { $ip=($dec-(intval($dec/256)*256)).".".$ip; $dec=(double) intval($dec/256); } else $ip="0.".$ip; $ip=$dec.".".$ip; return (string) $ip; } ?> /// the result is this: 0.0.0.0 but when i don't call the function the Decimal looks like this 1136272721 so it's printing the decimal but the function to convert it to a real IP is not working well. it should look like 89.255.25.25 *(not real ofc) have a nice day. Ty.
×
×
  • 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.