Selamlar Gdefender,

Burdaki ornek umarim sana yardimci olur. Sorularin varsa, sor.

Browserdeki sonuc:


Database:



Ve php kodumuz:

<?php


  function format_num($num, $precision = 2) {
   if ($num >= 1000 && $num < 1000000) {
    $n_format = number_format($num/1000,$precision).'K';
    } else if ($num >= 1000000 && $num < 1000000000) {
    $n_format = number_format($num/1000000,$precision).'M';
   } else if ($num >= 1000000000) {
   $n_format=number_format($num/1000000000,$precision).'B';
   } else {
   $n_format = $num;
    }
  return $n_format;
  } 


  function rev_format_num($num, $precision = 2) {
   if (strpos($num,'K') !== false) {
   $n_format = str_replace('K', " ", number_format($num*1000,$precision));
   } 
      else if (strpos($num,'M') !== false) {
    $n_format = str_replace('M', " ", number_format($num*1000000,$precision));
   } 
      else if (strpos($num,'B') !== false) {
  $n_format = str_replace('B', " ", number_format($num*1000000000,$precision));
   } 
      else {
   $n_format = $num;
    }
  return $n_format;
  } 




// Function Calls
$num1 = format_num(1200,1);
$num2 = format_num(1230000);
$num3 = format_num(1234000000,3);

echo format_num(1200,1);
echo format_num(1230000);
echo format_num(1234000000,3);


$con=mysqli_connect("localhost","root","","ornek");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
echo"<ul>"; 

$koy=mysqli_query($con,"INSERT INTO formatnumbertable (number1, number2, number3)
VALUES ('$num1', '$num2', '$num3')");
if($koy === FALSE) { 
    die(mysql_error()); // TODO: better error handling
}

$cek = mysqli_query($con, "SELECT number1,number2,number3 FROM formatnumbertable ");
if($cek === FALSE) { 
    die(mysql_error()); // TODO: better error handling
}
while($yaz = $cek->fetch_assoc()){ 
    $name1=$yaz["number1"]; 
     $name2=$yaz["number2"]; 
     $name3=$yaz["number3"]; 
    echo rev_format_num($name1); 
    echo "<br /> "; 
     echo rev_format_num($name2); 
    echo "<br /> "; 
     echo rev_format_num($name3); 
    echo "<br /> "; 
} 


?>