在显示之前对PHP中的结果进行排序

时间:2013-09-26 17:15:32

标签: php sorting

首先我要说的是,我对PHP非常陌生并尽我所能。也就是说,随意批评我的代码,但知道我已经知道了。

好的,所有这些代码现在都在运行。我只需要弄清楚为什么在显示结果之前我不能按“价格”排序。下面的代码是我认为应该进行排序的地方。

<?php 
$group = get_the_term_list( $post->ID, 'product_categories', '', ', ', '' );
$group = strip_tags($group);
$index = 'group';
foreach ($results as $tire) {
if ($tire->group == $group) { 
    if($tire->sort6 == "C" || $tire->sort6 == "D" || $tire->sort6 == "E" || $tire->sort6 == "F"){
            $test = (string) $tire->description;
            $tiresize = preg_split('/ /', $test);
            $warranty = substr($test,-3,2);
            if (!is_numeric($warranty))
                $warranty = "Please contact for more information.";
            else if ($warranty == 00)
                $warranty = "No mileage warranty";
            else
                $warranty = $warranty.",000 mile warranty";

        echo '<strong>'.'<font size="4" color="#000">'.'$'.number_format($tire->price, 2).'</font>'.'</strong>'.' - '.$tiresize[0].' '.$tire->sort6.' - '.$warranty.'<br/>';

    }else{
            $test = (string) $tire->description;
            $tiresize = preg_split('/ /', $test);
            $warranty = substr($test,-3,2);
            if (!is_numeric($warranty))
                $warranty = "Please contact for more information.";
            else if ($warranty == 00)
                $warranty = "No mileage warranty";
            else
                $warranty = $warranty.",000 mile warranty";

        //echo '<strong>'.'<font size="4" color="#000">'.'$'.number_format($price_string, 2).'</font>'.'</strong>'.' - '.'P'.$tiresize[0].' '.$tire->sort4.$tire->sort5.' - '.$warranty.'<br/>';

        echo '<strong>'.'<font size="4" color="#000">'.'$'.number_format($tire->price, 2).'</font>'.'</strong>'.' - '.'P'.$tiresize[0].' '.$tire->sort4.$tire->sort5.' - '.$warranty.'<br/>';

    }
    }  
    } 

?>  

这是您可以在其中查看完整代码的链接: http://pastie.org/8357831

0 个答案:

没有答案