HTML "How to get variabel in this calculate"

HTML "How to get variabel in this calculate"
0

#1
<?php
	include_once('../config/koneksi-apriori.php');
	$item1 = count($item) - 1; 
    $item2 = count($item);
    // MENDAPATKAN JUMLAH BARANG
    foreach ($item as $value) {
        $total_per_item[$value] = 0;
        foreach($belian as $item_belian) {            
            if(strpos($item_belian, $value) !== false) {
                $total_per_item[$value]++;
            }
        }
    }
    // MENDAPAT JUMLAH GABUNGAN
    for($i = 0; $i < $item1; $i++) {
        for($j = $i+1; $j < $item2; $j++) {
            $item_pair = $item[$i].'|'.$item[$j]; 
            $item_array[$item_pair] = 0;
            foreach($belian as $item_belian) {
                if((strpos($item_belian, $item[$i]) !== false) && (strpos($item_belian, $item[$j]) !== false)) {
                    $item_array[$item_pair]++;
                }
            }
        }
    }
     echo "<pre>";
     	foreach ($item_array as $ia_key => $ia_value) {
        $theitems = explode('|',$ia_key);
        for($x = 0; $x < count($theitems); $x++) {
            $item_name = $theitems[$x];
            $item_total = $total_per_item[$item_name];
            
            if ($item_total == 0) {
                $in_float = 0;
            }else{
               $in_float = $ia_value / $item_total; 
            }
            
            $in_percent = round($in_float * 100, 2);
            $alt_item = $theitems[ ($x + 1) % count($theitems)];
            echo "[*] $ia_key --> $item_name "."\r\n";
            echo  "[*] Confidence --> ".$ia_value." / ".$item_total." = ".$in_float."\r\n" ;
            echo "----> if buy $item_name then $alt_item with Confidence = ". $in_percent ."%\r\n";
            echo "===============================================================\r\n";
        }
    }
     echo "</pre>";
?>

i want to get variable $in_float more than 4.5%


#2

Not sure what you are asking exactly. What does file located at …/config/koneksi-apriori.php look like? Does it define what $item is? I believe $item is an array, but what does it contain. Does the file you include contain the $item inside it?


#3
<?php
$mysqli = new mysqli("localhost", "root", "", "bibitkita");// koneksi database 

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

if ($result = $mysqli->query("select ProductName from products", MYSQLI_USE_RESULT)) {
	while ($i = $result->fetch_row()) {
		$item[] = $i[0];
	}
    $result->close();
}

if ($result = $mysqli->query("select group_concat(products.ProductName separator ', ')
    from order_details left join products 
	 on (order_details.ProductID = products.ProductID)
	 group by order_details.OrderID", MYSQLI_USE_RESULT)) {	
	while ($b = $result->fetch_row()) {
		$belian[] = $b[0];
	}
	
    $result->close();
}

?>

#4

…/config/koneksi-apriori.php


#5

Still not sure what you are asking above. I see where you assign $in_float a value in the code below:

            if ($item_total == 0) {
                $in_float = 0;
            }else{
               $in_float = $ia_value / $item_total; 
            }

The value of $in_float will either be 0 or the result of the calc shown above. Can you explain more what you mean by getting $in_float more than 4.5%?

Since I can not see the actual values of the $item array and all other calculations seem to depend on the values in $item array, I do not know if you are expecting values higher than 4.5% for $in_float and you are not getting them or what.

Can you show me the exact contents of $item which gets created from the included file? If it is a large array don’t worry about it, but if it is not too big, copy/paste it here.