iall Posted March 2, 2016 Author Report Share Posted March 2, 2016 Labrīt. Biju rakstījis šādi: $categories = $conn->query("SELECT zid, nosaukums FROM ziedu_kategorijas ORDER BY nosaukums ASC"); $flowers = []; foreach ($categories as $category) { $flowers[$category['zid']] = "SELECT puku_nosaukums FROM ziedi WHERE ziedu_id = ? ORDER BY puku_nosaukums ASC, $category[zid]"; $categories->bind_param("s", $category['zid']); $categories->execute(); } Rezultāts - "Fatal error: Call to undefined method mysqli_result::bind_param()" Quote Link to comment Share on other sites More sharing options...
e-remit Posted March 2, 2016 Report Share Posted March 2, 2016 Un ko tavā kodā satur mainīgais `$categories`, kuram tu centies izsaukt metodi `bind_param()`? Quote Link to comment Share on other sites More sharing options...
iall Posted March 2, 2016 Author Report Share Posted March 2, 2016 (edited) Neuzmanības kļūda, atkal. Pārlaboju uz ko šādu: foreach ($categories as $category) { $flowers[$category['zid']] = "SELECT puku_nosaukums FROM ziedi WHERE ziedu_id = $category[zid] ORDER BY puku_nosaukums ASC, $category[zid]"; } Rāda šo: Notice: Undefined index: ziedu_id in C:\xampp\htdocs\lazdkalni\admin\inc\all-flowers.php on line 57 Kods: foreach ($categories as $category) { echo $category['nosaukums'].'<br />'; foreach ($flowers[$category['ziedu_id']] as $flower) <- 57 rindiņa { if(empty($flower['puku_nosaukums'])) { echo 'Ziedu nav!'; } else { echo $flower['puku_nosaukums']; } } } Pieņemu, ka ziedu_id nav izvilkts un tādēļ met kļūdu. Pilns kods: http://codepad.org/M8TIaf0O Edited March 2, 2016 by iall Quote Link to comment Share on other sites More sharing options...
jurchiks Posted March 2, 2016 Report Share Posted March 2, 2016 (edited) Izlasi piemēru: http://php.net/manual/en/mysqli.prepare.php#refsect1-mysqli.prepare-examples Tu tur tagad sāc izdomāt pats savas metodes. Otrkārt, tu tak pat neesi nokopējis manu kodu pareizi: foreach ($flowers[$category['ziedu_id']] as $flower) manā kodā bija: foreach ($flowers[$category['zid']] as $flower) Tu mācies par programmētāju or something? Un kas, pie velna, ir šitas: $flowers[$category['zid']] = "SELECT puku_nosaukums FROM ziedi WHERE ziedu_id = $cat ORDER BY puku_nosaukums ASC, $category[zid]"; ? Edited March 2, 2016 by jurchiks Quote Link to comment Share on other sites More sharing options...
iall Posted March 2, 2016 Author Report Share Posted March 2, 2016 (edited) Sasmējos! :) Viss bija pareizi nokopēts, negāja. Centos mazliet pielabot, paskatīties vai varbūt ir kas nepareizi nodefinēts, izsaukts. Nemācos par programmētāju, tīri hobija pēc. Pēc Tava dotā koda - Warning: Invalid argument supplied for foreach() (katrai rindai kur ir kvērijs). Edited March 2, 2016 by iall Quote Link to comment Share on other sites More sharing options...
jurchiks Posted March 2, 2016 Report Share Posted March 2, 2016 Loģiski, ka tur būs warning, jo tev tas SQL strings ir jāaizvieto ar reālu DB pieprasījumu, izmantojot mysqli. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 2, 2016 Report Share Posted March 2, 2016 Ir jāsaprot katra rindiņa lai programmētu! Quote Link to comment Share on other sites More sharing options...
Wuu Posted March 4, 2016 Report Share Posted March 4, 2016 Ir jāsaprot katra rindiņa lai programmētu! ctr+c => ctr+v no stack overflow arī strādā :D Quote Link to comment Share on other sites More sharing options...
iall Posted March 5, 2016 Author Report Share Posted March 5, 2016 (edited) @jurchiks - man sanāca mazliet īsāk. $sql2 = "SELECT * FROM ziedi JOIN ziedu_kategorijas ON ziedi.ziedu_id = ziedu_kategorijas.zid"; $result2 = mysqli_query($conn,$sql2); $names = array(); while($row2 = mysqli_fetch_assoc($result2)) { foreach ( $result2 as $row2){ $name = $row2['nosaukums']; if(!in_array($name, $names)){ $names[] = $name; echo '<br /><u>'.$name ."</u><br />"; } echo $row2['puku_nosaukums']."<br />"; } } Edited March 5, 2016 by iall Quote Link to comment Share on other sites More sharing options...
jurchiks Posted March 5, 2016 Report Share Posted March 5, 2016 Īsāk ne vienmēr ir labāk. Šāds kods ir sliktāk lasāms. Quote Link to comment Share on other sites More sharing options...
iall Posted March 5, 2016 Author Report Share Posted March 5, 2016 Varbūt, bet varbūt arī nē! :) Paldies par palīdzību visiem. @jurchiks - alus no manis, par uzvešanu uz pareizā ceļa. Quote Link to comment Share on other sites More sharing options...
jurchiks Posted March 5, 2016 Report Share Posted March 5, 2016 (edited) Nav par ko. Diemžēl es nedzeru alu :( P.S. Ja ir gribēšana brīvdienās pamācīties programmēšanu, http://codeschool.com piedāvā šajās brīvdienās visus kursus bez maksas. Tur ir kaudze tiešām kvalitatīvu kursu, tā kā iesaku izmantot. Edited March 5, 2016 by jurchiks Quote Link to comment Share on other sites More sharing options...
briedis Posted March 5, 2016 Report Share Posted March 5, 2016 Īsāk ne vienmēr ir labāk. Šāds kods ir sliktāk lasāms. Muļķības, šis kods ir labi lasāms. Tavs kods gan bija diezgan briesmīgs, bloated, un kurš raksta kvēriju ciklā? Quote Link to comment Share on other sites More sharing options...
codez Posted March 5, 2016 Report Share Posted March 5, 2016 Muļķības, šis kods ir labi lasāms. Tavs kods gan bija diezgan briesmīgs, bloated, un kurš raksta kvēriju ciklā? Man šito bija slinkums rakstīt. Quote Link to comment Share on other sites More sharing options...
jurchiks Posted March 6, 2016 Report Share Posted March 6, 2016 (edited) Mans kods bija lasāms vēl vieglāk. 1. Salasi datus. 2. Izvadi datus. As simple as possible, separation of concerns, etc. Par līniju skaitu tev nemaksā (un ja maksā, tad ko tu tur vispār dari?). >kurš raksta kvēriju ciklā? Es rakstu, acīmredzot. Un ja tu nepamanīji, tad es uzreiz piedāvāju arī optimālāku risinājumu, so piss off. Edited March 6, 2016 by jurchiks 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.