我有这样的代码:
function artykul_firmy_z_branzy($art_id, $limit) {
return select("
select f.id from artykuly a, firmy f where a.display = true
and a.id_branzy = f.branza_id and a.id = :id and f.profil <> 0 order by f.profil desc, f.firma asc limit ${limit}
", array('id' => $art_id));
}
这段代码应该从sql数据库中选择一些行并对其进行排序,它的效果很好,但结果却是最大的&#34; f.profil&#34;总是在列表的末尾,当我将限制更改为&#34; 1&#34;,然后我只得到最大f.profil的结果,所以排序有效,但如何在第一个位置显示这个?
模板中的代码,显示结果:
{% if firmy_z_branzy_logo %}
<div class="firmy-z-branzy">
<img src="/static/screw.png" class="label-screw" /> <div class="label-title">FIRMY Z TEJ BRANŻY</div>
<div style="clear: both;"></div>
{% for i in firmy_z_branzy_logo %}
<div class="firma-branza"><a href="/wizytowka/{{ i.id_firmy }}"><img src="/{{ i.sciezka }}m/{{ i.plik }}" / style="margin-bottom:6px;"></a>{{ i.opis }}</div>
{% endfor %}
</div>
{% endif %}
答案 0 :(得分:0)
也许可以试试这个INNER JOIN:
SELECT a.*, f.* FROM artykuly a
INNER JOIN firmy f ON a.id_branzy = f.branza_id AND a.display = true AND a.id = :id AND f.profil <> 0
ORDER BY f.profil desc, f.firma LIMIT ${limit}