douhuan3448 2013-06-26 16:33
浏览 39

如何在php中删除未定义的row()错误

i get the code of knn algorithim from http://jameshamilton.eu/old/datamining/k-nearest_neighbour.php?source. i got error in undefined function row .kindly help me in removing this error.this the akgo of k -nearest algorithim

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content="K Nearest Neighbour Algorithm - Data Mining" />
<meta name="keywords" content="k nearest neighbour, data mining, php, computer science, james hamilton" />
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="robots" content="all" />
<meta name="revisit-after" content="1 days" />

<title>K Nearest Neighbour Algorithm - Data Mining</title>
<?php
include('admin_nb.php');
 // $date=$_GET['id'];echo"</br>";
  //$d=$_GET['id1'];

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db=mysql_select_db("vas1",$con);


?>

</head>

<body>

<?php
if(isset($_GET['source'])) {
    highlight_file(__FILE__);
}else{
if(!isset($_POST['k'])) $_POST['k'] = 3;
?>


    <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
    K:&nbsp;
    <select name="k">
        <?php foreach(range(1, 10) as $k) { ?>
            <option value="<?=$k?>" <?php if($k == $_POST['k']) { ?> selected="selected"<?php } ?>><?=$k?></option>
        <?php } ?>
    </select>


    <table id="patients" cellpadding="3" cellspacing="0">
        <tr>

  <th>highest_dialled_call_type</th>
   <th>Age_less_than_30</th>
   <th>Age_greater_than_30</th>
   <th>Payment_on_time</th>
   <th>Pkg_activation</th>
   <th>Customer_profile</th>
   <th>Churn</th>
   <th>Proposed_pkg</th>
   <th>Distance</th>


        </tr>

    <?php

        /*
            --
            -- Table structure for table `datamining_diagnoses`
            --

            CREATE TABLE IF NOT EXISTS `datamining_diagnoses` (
              `id` int(11) NOT NULL auto_increment,
              `sorethroat` tinyint(4) NOT NULL default '0',
              `fever` tinyint(4) NOT NULL default '0',
              `swollenglands` tinyint(4) NOT NULL default '0',
              `congestion` tinyint(4) NOT NULL default '0',
              `headache` tinyint(4) NOT NULL default '0',
              `diagnosis` varchar(50) NOT NULL default '',
              PRIMARY KEY  (`id`)
            ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

            --
            -- Dumping data for table `datamining_diagnoses`
            --

            INSERT INTO `datamining_diagnoses` (`id`, `sorethroat`, `fever`, `swollenglands`, `congestion`, `headache`, `diagnosis`) VALUES
            (1, 1, 1, 1, 1, 1, 'Strepthroat'),
            (2, 0, 0, 0, 1, 1, 'Allergy'),
            (3, 1, 1, 0, 1, 0, 'Cold'),
            (4, 1, 0, 1, 0, 0, 'Strepthroat'),
            (5, 0, 1, 0, 1, 0, 'Cold'),
            (6, 0, 0, 0, 1, 0, 'Allergy'),
            (7, 0, 0, 1, 0, 0, 'Strepthroat'),
            (8, 1, 0, 0, 1, 1, 'Allergy'),
            (9, 0, 1, 0, 1, 1, 'Cold'),
            (10, 1, 1, 0, 1, 1, 'Cold');
        */

        /*
            function getRows takes an SQL query string (and a optional array key type - NUM or ASSOC)
            and returns and array containing all the rows of the query.

                define(ASSOC, 1);
                define(NUM, 2);

                function getRows($sql, $type=ASSOC) {
                    $result = mysql_query($sql);
                    if($type == ASSOC) {
                        while($row = mysql_fetch_array($result))
                            $ret[] = $row;
                    }else if($type == NUM) {
                        while($row = mysql_fetch_row($result))
                            $ret[] = $row;
                    }else{
                        die("type should be NUM or ASSOC");
                    }
                    return $ret;
                }
        */


        $rows =getRows("SELECT * FROM knowledge_base;", NUM);


        $closest = -1;

        if(isset($_POST['diagnose'])) {
            $distance = array_fill(0, count($rows), 0);

            $instance = $_POST['instance'];

            for($i = 0; $i < count($rows); $i++) {

                for($j = 1; $j < 8; $j++) {
                    if($rows[$i][$j] != $instance[$j])
                        $distance[$i]++;
                }

            }


            asort($distance);

            $kclosest = array();

            foreach($distance as $key => $d)
                if(++$x <= $_POST[k]) {
                     $kclosest[$rows[$key][8]]++;
                     $newdistance[$key] = $d;
                }

            arsort($kclosest);
            $diagnosis = key($kclosest);

       }

        $a = 0;
        foreach($rows as $row) {

        ?>
            <tr <?php if(isset($newdistance[$a])) { ?> class="selected"<?php } ?>>
                 <td><?=$row[0] == international ? "international" : "onnet" : "offnet"; ?></td>
                <td><?=$row[1] == no ? "no" : "yes"; ?></td>
                <td><?=$row[2] == no ? "no" : "yes"; ?></td>
                <td><?=$row[3] == no ? "no" : "yes"; ?></td>
                <td><?=$row[4] == no ? "no" : "yes"; ?></td>
      <td><?=$row[5] == no ? "new" : "loyal"; ?></td>
                <td><?=$row[6] == no ? "no" : "yes"; ?></td>
                <td><?=$row[7]?></td>
                <td><?=$distance[$a++]?></td>
            </tr>

        <?php

        }
        ?>
        <tr>

                <td><input type="hidden" name="instance[]" value="11" />11</td>
                <td><select name="instance[]">
                        <option value="0"<?php if($_POST['instance'][0] == "international") echo "selected=\"selected\"";?>>international</option>
                        <option value="1"<?php if($_POST['instance'][0] == "onnet") echo "selected=\"selected\"";?>>onnet</option>
      <option value="2"<?php if($_POST['instance'][0] == "offnet") echo "selected=\"selected\"";?>>offnet</option>
                    </select>
                </td>
                <td><select name="instance[]">
                        <option value="0"<?php if($_POST['instance'][1] == "0") echo "selected=\"selected\"";?>>no</option>
                        <option value="1"<?php if($_POST['instance'][1] == "1") echo "selected=\"selected\"";?>>yes</option>
                    </select>
                </td>
                <td><select name="instance[]"&gt.

error come at line :$rows =getRows("SELECT * FROM knowledge_base;", NUM); error is : Fatal error: Call to undefined function getRows() in C:\wamp\www\vas1\knn1.php on line 122 kindly help in removing this error

  • 写回答

2条回答 默认 最新

  • douxing2156 2013-06-26 16:37
    关注

    You've commented out the definition of the getRows() function.

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题