-1

我最初在这里问了这个问题:

http://www.daniweb.com/web-development/php/threads/439484/why-arent-more-echos-being-executed

上传到服务器(表单):

http://cs4.sunyocc.edu/~jddancks/onestopshop/index.php

sort_mysql 结果对其他查询的数组进行排序,并返回在所有数据数组中找到的二维数据数组。

编辑:我用回声解决了这个问题,现在我有这个功能的问题(我认为):

function sort_mysql_results()
{
    echo "<p>begin smr</p>";
    $match=array();
    $c_match=0;
    $num_it = 0;
    $num_args = func_num_args();
    $c = 0;
    $args = func_get_args();
    while(isset($args[0][$num_it]))
    {
        echo "<p>sort mysql beginning of loop</p>";
        $skip=false;
        $name = $args[0][$num_it]['item_name'];
        $i=1;
        while(isset($args[$i])&&!$skip)
        {
            $skip = !check($args[$i],$name);
            $i++;
        }
        $num_it++;
        if(!$skip)
        {
            $match[$c_match] = $args[0];
            $c_match++;
        }
    }
    echo "<p>Num args: ".$num_args.", Iterations: ".$num_it."</p>";
    return $match;
}

该函数的调用方式如下:

$match = sort_mysql_results(sort_soundex_results($queries[0]),get_array($queries[1]));

现在 $match 应该是一个数组。出于某种原因,它不是。我尝试将结果打印到这样的表中:

if(count($match)>0)
{
    $num=0;
    echo "<table>\n
    <tr>\n
    <td>Name</td><td>Category</td><td>Description</td>\n
    </tr>\n";
    while(isset($match[$num]))
    {
        echo "<tr>\n
        <a href=\"product2.php?id=".$match[$num]['ItemID']."\"><td>".$match[$num]['item_name']."</td><td>".$match[$num]['cat_name']."</td><td>".$match[$num]['descr']."</td></a>\n
        </tr>\n";
        $num++;
    }
    echo "</table>\n";
}
else
{
    echo "<p>No matches found. Go back and try different search criteria</p>\n";
}

作为参考,正在查询的 mysql 表如下所示:

 +-------------+--------------+------+-----+---------------------+----------------+
 | Field       | Type         | Null | Key | Default             | Extra          |
 +-------------+--------------+------+-----+---------------------+----------------+
 | item_name   | varchar(100) | NO   |     |                     |                | 
 | ItemID      | mediumint(9) | NO   | PRI | NULL                | auto_increment | 
 | cat_name    | varchar(45)  | NO   |     |                     |                | 
 | userID      | mediumint(9) | NO   |     |                     |                | 
 | descr       | text         | NO   |     |                     |                | 
 | image       | tinytext     | YES  |     | NULL                |                | 
 | date        | timestamp    | NO   |     | CURRENT_TIMESTAMP   |                | 
 | highest_bid | decimal(6,2) | NO   |     | 0.00                |                | 
 | time_expire | timestamp    | NO   |     | 0000-00-00 00:00:00 |                | 
 +-------------+--------------+------+-----+---------------------+----------------+

编辑:希望你还在我身边。我做了一些进一步的调试:

...
if(count($match)>0)
{
    echo "<p>space</p><h2>In IF STATEMENT VALUE OF MATCH BEFORE WHILE LOOP</h2><p>space</p>\n";
    echo "<p>space</p><p>space</p><p>space</p>\n";
    var_dump($match);
    echo "<p>space</p><p>space</p><p>space</p>\n";
    echo "<h2>VALUE OF match[num]</h2>\n";
    echo "<p>space</p><p>space</p><p>space</p>\n";
    var_dump($match[0]);
    echo "<p>space</p><p>space</p><p>space</p>\n";
...

看一下这个:

 In IF STATEMENT VALUE OF MATCH BEFORE WHILE LOOP

 space

 space

 space

space

array(1) { [0]=> array(1) { [0]=> array(12) { ["item_name"]=> string(10) "Squat Rack" ["ItemID"]=> string(1) "8" ["cat_name"]=> string(16) "Sports Equipment" ["userID"]=> string(1) "1" ["descr"]=> string(25) "Comes with 275 lbs plates" ["image"]=> string(14) "squat_rack.jpg" ["date"]=> string(19) "2012-10-15 09:34:36" ["highest_bid"]=> string(4) "0.00" ["time_expire"]=> string(19) "2012-12-01 00:00:01" ["src"]=> string(4) "S362" ["src2"]=> string(4) "S362" ["result"]=> string(1) "1" } } }
 space

 space

 space

 VALUE OF match[num]

 space

 space

 space

 array(1) { [0]=> array(12) { ["item_name"]=> string(10) "Squat Rack" ["ItemID"]=> string(1) "8" ["cat_name"]=> string(16) "Sports Equipment" ["userID"]=> string(1) "1" ["descr"]=> string(25) "Comes with 275 lbs plates" ["image"]=> string(14) "squat_rack.jpg" ["date"]=> string(19) "2012-10-15 09:34:36" ["highest_bid"]=> string(4) "0.00" ["time_expire"]=> string(19) "2012-12-01 00:00:01" ["src"]=> string(4) "S362" ["src2"]=> string(4) "S362" ["result"]=> string(1) "1" } }
 space

 space

 space

看起来应该是的。这里发生了什么???

4

1 回答 1

0

这是修改后的 sort_mysql_results:

function sort_mysql_results()
{
    echo "<p>begin smr</p>";
    $match=array();
    $c_match=0;
    $num_it = 0;
    $c = 0;
    $args = func_get_args();
    while(isset($args[0][$num_it]))
    {
        echo "<p>sort mysql beginning of loop</p>";
        $skip=false;
        $name = $args[0][$num_it]['item_name'];
        $i=1;
        while(isset($args[$i])&&!$skip)
        {
            $skip = !check($args[$i],$name);
            $i++;
        }
        if(!$skip) //if found in another parameter
        {
            $match[$c_match] = $args[0][$num_it];
            $c_match++;
        }
        $num_it++;
    }
    echo "<p>Num args: ".$num_args.", Iterations: ".$num_it."</p>";
    var_dump($match);
    return $match;
}

基本上原始只在找到查询后保存了一个并存储了 2D 数组,而不是使 $match 成为 3D 数组的单个数组。感谢宇智波斑发帖

于 2012-11-16T20:23:02.950 回答