Blumish Posted July 2, 2011 Report Share Posted July 2, 2011 Sveiki! Kas man ir jāpieliek klāt šim kodam, lai rādītos cik ierakstu ir katrā kategorījā. Paldies <?php $catList = ""; $id = ""; if(!isset($currentCat)) $currentCat = ""; if (isset($_GET["category"])) $currentCat = mysql_real_escape_string($_GET["category"]); $result = mysql_query("SELECT * FROM md_categories order by cat_order"); if (!$result){ print("Houston we have a problem: " . mysql_error()); exit(); } $categoryCounter =0; while ($row = mysql_fetch_array($result)){ if ($currentCat == $row["cat_id"]){ $id ='id="current"'; $categoryCounter++; } $catList .= "<li $id><a href='index.php?category=" . $row["cat_id"] . $keyOut . "'>" . $row["cat_name"] . "</a></li>\n" ; $id = ""; } $idNewItem = $idHome = ""; if ($categoryCounter < 1){ if(strpos($_SERVER['PHP_SELF'], "newItem") > 0) $idNewItem = "id='current'"; else $idHome = "current"; } ?> Quote Link to comment Share on other sites More sharing options...
101111 Posted July 2, 2011 Report Share Posted July 2, 2011 Datubāzes pieprasījuma jāpiedžoino ierakstu skaits un saraksta izvadīšanas daļā tas jāizvada Quote Link to comment Share on other sites More sharing options...
Rincewind Posted July 2, 2011 Report Share Posted July 2, 2011 Kaut kā tā: $result = mysql_query(" SELECT md_categories.*, COUNT(products.cat) AS skaits FROM products JOIN md_categories on products.cat = md_categories.id GROUP BY products.cat"); Quote Link to comment Share on other sites More sharing options...
Blumish Posted July 2, 2011 Author Report Share Posted July 2, 2011 varbūt ludzu precizāk varat pateikt kas ir jādara.. Kas ir jāpieliek klāt! Šī ir kategorīju izvade: <li id='<?php print($idHome); ?>'><a href='index.php?a=1<?php echo $keyOut;?>'><?php echo STR_ALLADDS ?></a></li> <?php print($catList); ?> <li <?php print($idNewItem); ?>><a href="newItem.php?a=1<?php echo $keyOut;?>"><?php echo STR_POSTSOMETHING ?></a></li> Quote Link to comment Share on other sites More sharing options...
404 Posted July 2, 2011 Report Share Posted July 2, 2011 Jāsamaina selekts uz iepriekšējā postā ar karotīti iedoto,un linka izvadē jāpieliek vajadzīgā $row atslēga. Quote Link to comment Share on other sites More sharing options...
Blumish Posted July 2, 2011 Author Report Share Posted July 2, 2011 Jāsamaina selekts uz iepriekšējā postā ar karotīti iedoto,un linka izvadē jāpieliek vajadzīgā $row atslēga. varbut kads var palidzēt to izdarit? Quote Link to comment Share on other sites More sharing options...
404 Posted July 2, 2011 Report Share Posted July 2, 2011 Noteikti ka var.Es pat teiktu,ka to var izdarīt jebkurš,kas ar php strādā vismaz gadu. Quote Link to comment Share on other sites More sharing options...
Blumish Posted July 2, 2011 Author Report Share Posted July 2, 2011 Noteikti ka var.Es pat teiktu,ka to var izdarīt jebkurš,kas ar php strādā vismaz gadu. Tu nebūtu tik laipns un nepalīdzētu? Quote Link to comment Share on other sites More sharing options...
404 Posted July 2, 2011 Report Share Posted July 2, 2011 (edited) Ja tu parādītu,ko mēģināji,un kas nesanāca,tad domāju,ka jebkurš noziedos nedaudz laika,lai palīdzētu izprast.Tev tikai ir jārada iespaids ka tu kaut ko dari,nevis bičo kodu. :) Edited July 2, 2011 by 404 Quote Link to comment Share on other sites More sharing options...
Blumish Posted July 2, 2011 Author Report Share Posted July 2, 2011 (edited) Ja tu parādītu,ko mēģināji,un kas nesanāca,tad domāju ka jebkurš,noziedos nedaudz laika,lai palīdzētu izprast.Tev tikai ir jārada iespaids ka tu kaut ko dari,nevis bičo kodu. :) Nu es mēģināju šādi. <?php $result = mysql_query(" SELECT md_categories.*, COUNT(products.cat) AS skaits FROM products JOIN md_categories on products.cat = md_categories.id GROUP BY products.cat"); $catList = ""; $id = ""; if(!isset($currentCat)) $currentCat = ""; if (isset($_GET["category"])) $currentCat = mysql_real_escape_string($_GET["category"]); $result = mysql_query("SELECT * FROM md_categories order by cat_order"); if (!$result){ print("Houston we have a problem: " . mysql_error()); exit(); } $categoryCounter =0; while ($row = mysql_fetch_array($result)){ if ($currentCat == $row["cat_id"]){ $id ='id="current"'; $categoryCounter++; } $catList .= "<li $id><a href='index.php?category=" . $row["cat_id"] . $keyOut . "'>" . $row["cat_name"] . "</a></li>\n" ; $id = ""; } $idNewItem = $idHome = ""; if ($categoryCounter < 1){ if(strpos($_SERVER['PHP_SELF'], "newItem") > 0) $idNewItem = "id='current'"; else $idHome = "current"; } ?> Un pie izvades <li id='<?php print($idHome); ?>'><a href='index.php?a=1<?php echo $keyOut;?>'><?php echo STR_ALLADDS ?></a></li> <?php print($catList); ?> <?php print($skaits); ?> <li <?php print($idNewItem); ?>><a href="newItem.php?a=1<?php echo $keyOut;?>"><?php echo STR_POSTSOMETHING ?></a></li> Edited July 2, 2011 by Blumish Quote Link to comment Share on other sites More sharing options...
404 Posted July 2, 2011 Report Share Posted July 2, 2011 (edited) Vienkārši ieliekot augšā mainīgo,tam nav jēgas,ja tālāk skriptā tas vienalga tiek par jaunu pārrakstīts ar citu vērtību.Paštuko,ko dara mainīgais $result,un kur tam būtu jāatrodas.Izvadi mysql rezultātu debug modē ar print_r(mysql_fetch_assoc($result)); Ja viss ir ok,pašpiko kādas atslēgas ar kādām vērtībām izvadās,un vienkārši pieliec vajadzīgo iekš linka.Īsāk sakot,skriptu vajag vispirms mēģināt saprast,pēc tam debugot,un ja neizdodas,tad kāds vienmēr norādīs uz kļūdām.Tā ir arī šajā gadījumā. Edited July 2, 2011 by 404 Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 2, 2011 Report Share Posted July 2, 2011 Labi pateikts, 404! Quote Link to comment Share on other sites More sharing options...
Blumish Posted July 2, 2011 Author Report Share Posted July 2, 2011 (edited) Var iztikt ari ar sho vaine? <?php echo $categoryCounter ?> Bet cik saprotu, man vins jasavieno ar: <?php print($catList) ; ?> lai ierakstu skaits radiitos pie katras kategoriijas Bet es isti pareizi to nemaku izdarit Edited July 2, 2011 by Blumish Quote Link to comment Share on other sites More sharing options...
Blumish Posted July 3, 2011 Author Report Share Posted July 3, 2011 Izpalidziigi seit visi! Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 3, 2011 Report Share Posted July 3, 2011 404'ais jau izskaidroja, kāpēc neviens nepalīdz. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.