无法从数据库中排序多个表数据?

时间:2013-05-10 14:47:41

标签: php

我从列“cena”(eng:price)中排序数据时遇到了一些问题。

我制作了多种语言的网站,我为每种语言制作了3个表格,en_slike,ger_slike(塞尔维亚语,英语,德语),我想在一个页面中显示我可以按价格(cena)对数据进行排序date(slike_id),当我运行页面时,一切都很好,但是当我尝试按照cena(价格)排序图片时,什么都没有发生,为什么?

这是在工作之前:

这是图片选择功能的代码,该功能在Manage:

类中
public static function Select_Slike(){
        if(isset($_POST['btnsort']))
        {
            if(isset($_POST['sort']))
            {
                if($_POST['sort']=="cena")
                {   
                    $query = "(select * from slike order by cena desc) 
                        union all
                        (select * from en_slike order by cena desc)
                        union all
                        (select * from ger_slike order by cena desc)
                        ";

                    $rez = mysql_query($query);
                    while($row = mysql_fetch_array($rez))
                    {
                        echo '<div id="block1"><h5 id="naslov">'.$row['naslov'].'</h5><h5 id="cena">'.$row['cena'].'</h5><img src="images/'.$row['string'].'.jpg" class="slike"/><h5 id="materijal">'.$row['materijal'].'</h5><h5 id="dimenzije">'.$row['dimenzije'].'</h5></div>';
                    }
                }
                else
                {
                    $query =   "(select * from slike order by slike_id desc) 
                                union all
                                (select * from en_slike order by slike_id desc)
                                union all
                                (select * from ger_slike order by slike_id desc)
                                ";

                    $rez = mysql_query($query);
                    while($row = mysql_fetch_array($rez))
                    {
                        echo '<div id="block1"><h5 id="naslov">'.$row['naslov'].'</h5><h5 id="cena">'.$row['cena'].'</h5><img src="images/'.$row['string'].'.jpg" class="slike"/><h5 id="materijal">'.$row['materijal'].'</h5><h5 id="dimenzije">'.$row['dimenzije'].'</h5></div>';
                    }
                }
            }   
        }
        else
        {
            $query =   "(select * from slike order by slike_id desc) 
                        union all
                        (select * from en_slike order by slike_id desc)
                        union all
                        (select * from ger_slike order by slike_id desc)
                        ";

            $rez = mysql_query($query);

            while ($row = mysql_fetch_array($rez)) 
            { 
                echo '<div id="block1"><h5 id="naslov">'.$row['naslov'].'</h5><h5 id="cena">'.$row['cena'].'</h5><img src="images/'.$row['string'].'.jpg" class="slike"/><h5 id="materijal">'.$row['materijal'].'</h5><h5 id="dimenzije">'.$row['dimenzije'].'</h5></div>';
            }
        }   
    }

这是body php / html代码:

<body>
    <form action="" method="post">
    <div id="sortiranje">
        <select name="sort">
            <option value="date">Datum</option>
            <option value="cena">Cena</option>
        </select><input type="submit" name="btnsort" value="sort"/>
    </div>
    </form>
    <div id="slike_blok">
    <?php
    try{
    Manage::Select_Slike();
    }
    catch(Exception $e){
        die("<center><font size='42' color='red' weight='100'>SERVER DATABASE ERROR! ".$e->Message()."</font><center>");
    }
    ?>
    </div>
</body>

1 个答案:

答案 0 :(得分:1)

尝试这样的顺序应该是所有联盟的结束

public static function Select_Slike(){
   if(isset($_POST['btnsort']))
   {
       if(isset($_POST['sort']))
       {
          if($_POST['sort']=="cena")
           {   
              $query = "(select * from slike) 
              union all
              (select * from en_slike)
              union all
             (select * from ger_slike) order by cena desc";

$rez = mysql_query($query);
while($row = mysql_fetch_array($rez))
{
echo '<div id="block1"><h5 id="naslov">'.$row['naslov'].'</h5><h5 id="cena">'.$row['cena'].'</h5><img src="images/'.$row['string'].'.jpg" class="slike"/><h5 id="materijal">'.$row['materijal'].'</h5><h5 id="dimenzije">'.$row['dimenzije'].'</h5></div>';
}
}
else
{
$query =   "(select * from slike) 
union all
(select * from en_slike)
union all
(select * from ger_slike) order by slike_id desc
";

$rez = mysql_query($query);
while($row = mysql_fetch_array($rez))
{
echo '<div id="block1"><h5 id="naslov">'.$row['naslov'].'</h5><h5 id="cena">'.$row['cena'].'</h5><img src="images/'.$row['string'].'.jpg" class="slike"/><h5 id="materijal">'.$row['materijal'].'</h5><h5 id="dimenzije">'.$row['dimenzije'].'</h5></div>';
}
}
}   
}
else
{
$query =   "(select * from slike) 
union all
(select * from en_slike)
union all
(select * from ger_slike) order by slike_id desc
";

$rez = mysql_query($query);

while ($row = mysql_fetch_array($rez)) 
{ 
echo '<div id="block1"><h5 id="naslov">'.$row['naslov'].'</h5><h5 id="cena">'.$row['cena'].'</h5><img src="images/'.$row['string'].'.jpg" class="slike"/><h5 id="materijal">'.$row['materijal'].'</h5><h5 id="dimenzije">'.$row['dimenzije'].'</h5></div>';
}
}   
}