PHP:在echo不执行时帮助排除故障?

时间:2012-11-10 20:29:34

标签: php echo php4

我原来问这个问题:

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

上传到服务器(表单):

http://cs4.sunyocc.edu/~j.d.dancks/onestopshop/index.php

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

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

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

看起来应该是这样的。这是怎么回事?

1 个答案:

答案 0 :(得分: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数组。感谢Madara Uchiha发布