Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want an arrray like this


PHP
$data = array("1" => 10, "2" => 20, "3" => 5, "4" => 30,
"5" => 17, "6" => 13, "7" => 6, "8" => .0027, "9" => 28,
"10" => 31, "11" => 88, "12" => 13, "13" => 26,
"14" => 47, "15" => 3);




but i have written a code for that

PHP
$i=0;
while($row = mysqli_fetch_array($result))
  {
    $i++;


if($row[0]=="" || $row[1]=="")
{}else

    {

    if($x=="")
    {
      $y='"'.$row[0].'"';
    $z=" "."=>"." ";
    $a=" ".$row[1]." ";

        $x=$y.$z.$a;
    }else
    {

    $y='"'.$row[0].'"';
  $z=" "."=>"." ";
    $a=" ".$row[1]." ";
    $x=$x." , ". $x=$y.$z.$a;
    }

    }


  }




but its output is not correct please help me to correct to obtain the above pattern
Posted
Updated 8-Mar-13 4:45am
v2
Comments
joshrduncan2012 8-Mar-13 10:50am    
What is the output you are getting that is not correct?
vishnulalr 8-Mar-13 10:54am    
this is a sample output


"115.114.130.49" => 10950.8067479674,"115.114.130.85" => 10950.8067479674,"115.114.85.245" => 10950.8067479674,"117.206.48.1" => 21901.6134959348,"120.29.215.29" => 10950.8067479674,"127.0.0.1" => 4504.6714634146,"173.194.36.41" => 10950.8067479674,"180.87.15.69" => 10950.8067479674,"180.87.38.5" => 10950.8067479674,"209.85.241.189" => 10950.8067479674,"209.85.243.158" => 10950.8067479674,"216.187.113.68" => 10950.8067479674,"216.187.114.146" => 10950.8067479674,"216.187.114.150" => 10950.8067479674,"216.187.114.197" => 10950.8067479674,"216.187.120.170" => 10950.8067479674,"216.6.99.13" => 10950.8067479674,"216.6.99.6" => 10950.8067479674,"218.248.168.118" => 21901.6134959348,"64.86.31.49" => 10950.8067479674,"64.86.31.6" => 10950.8067479674,"65.39.148.34" => 10950.8067479674,"66.110.8.34" => 10950.8067479674,"66.249.94.73" => 10950.8067479674,"72.14.223.201" => 10950.8067479674,"72.14.232.101" => 10950.8067479674,"80.231.200.14" => 10950.8067479674,"80.231.217.17" => 10950.8067479674,"80.231.217.2" => 10950.8067479674,"codeproject.com" => 10950.8067479674,"fe80::752c:50ea:abc8:4083" => 4504.6714634146,"google.com" => 10950.8067479674
DinoRondelly 8-Mar-13 15:57pm    
Whats coming back in $row[0] and $row[1]?
vishnulalr 9-Mar-13 1:51am    
for $row[0] is a list of ip stored in db as varchar

and $row[1] is a list of packets in db as varchar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900