Jump to content
php.lv forumi

apvienot kverijus.


anonīms

Recommended Posts

2 tabulas

(faili_kategorijas (id, name)), (faili (name, kategorija))

 

kverijs, kas izvada kategorijas un iekšā saskaitam failus.

Kā varētu šos 2 kverijus apvienot vienā?

$failu_kategorijas = mysql_query("
     SELECT 
     id, name 
     FROM 
     faili_kategorijas 
     ORDER BY name ASC") or die(mysql_error());
     echo '<table>';
     while($cat = mysql_fetch_assoc($failu_kategorijas))
     {
     $files_in_cat = mysql_fetch_assoc(queryy("SELECT count(id) AS count FROM faili WHERE kategorija = '".$cat['id']."'"));
}
echo '</table>';

Rekspektīvi, lai saskaiti cik faili ir jau kverijā.

Mēģināju šādi

      SELECT 
     t1.id AS id, t1.name AS name 
     FROM 
     faili_kategorijas AS t1, faili AS t2
     ORDER BY name ASC

 

kā tikko pievienoju to faili AS t2. Tā while neko vairs neizvada un arī neizmet erroru..

Help

 

 

EDIT: doh. vinš neko nerādija tapēc, ka faili bija tukši

 

kr4,

      SELECT 
     t1.id AS id, t1.name AS name, count(t2.id) AS files_count 
     FROM 
     faili_kategorijas AS t1, faili AS t2 
     WHERE t1.id = t2.kategorija

Edited by anonīms
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...