Chapman Posted January 27, 2010 Report Share Posted January 27, 2010 (edited) // Connect to MSSQL and select the database $link = mssql_connect($host, $username, $password); mssql_select_db('SecKeyPrior'); // Select all our records from a table $nod_query = mssql_query('SELECT * FROM S_Nod'); $nod_count = mssql_num_rows($nod_query); for ( $a == 1; $a == $nod_count; $a++ ) { $nod_a = mssql_query("SELECT Nod_Nos From S_Nod Where Id_Nod='$a' "); print $nod_a; } pašlaik man šis skripts neizvada neko, kāpēc tā? Manupŗat, vajadzēja izvadīt Nod_Nos ierakstus no DB! Edited January 27, 2010 by Chapman Quote Link to comment Share on other sites More sharing options...
2easy Posted January 27, 2010 Report Share Posted January 27, 2010 tāpēc ka $a == $nod_count ir false Quote Link to comment Share on other sites More sharing options...
eT` Posted January 27, 2010 Report Share Posted January 27, 2010 (edited) saskaiti rezultātus labāk ar $a = mssql_query(SELECT COUNT(*) AS c FROM tabula) $b = mssql_result($a, 0) for($i=1;$i<=$b;$i++) { $c = mssql_query("SELECT Nod_Nos From S_Nod Where Id_Nod='$i' "); $d = mssql_fetch_assoc($c); $vards = $d["Nod_nos"]; print $vards; } mby mssql sintaksē nav fetch vai result es īsti nezinu :D es rakstīju kā būtu ar mysql :D bet nu principu gan jau saprati :) Edited January 27, 2010 by eT` Quote Link to comment Share on other sites More sharing options...
Chapman Posted January 27, 2010 Author Report Share Posted January 27, 2010 SELECT COUNT(*) AS c FROM tabula kas ir tas c? Quote Link to comment Share on other sites More sharing options...
Pentiums Posted January 27, 2010 Report Share Posted January 27, 2010 ierakstu skaits Quote Link to comment Share on other sites More sharing options...
Maris-S Posted January 27, 2010 Report Share Posted January 27, 2010 Es domāju Chapman jautāja par pašu 'AS c' izmantošanu, šajā gadījumā tas ir lauka aliass, Tu tādu vari piešķirt un kolonas nosaukums būs nevis 'count(*)', bet gan 'c', ērtāk pašam būs pie izvadīšanas. Šeit gan es neesmu pārliecināts vai sintakse mssqlam ir tāda pati ka mysqlam, bet iespējams ka strādās. Es kādu laiku skatījos uz šo kodu kopumā (to ko Chapman iepostēja pašu pirmo), tā arī dziļajā koda domā neiebraucu, vai tad nav pareizāk rīkoties sekojoši: // Connect to MSSQL and select the database $link = mssql_connect($host, $username, $password); mssql_select_db('SecKeyPrior'); // Select all our records from a table $nod_query = mssql_query('SELECT Nod_Nos From S_Nod'); if (is_resource($nod_query) && mssql_num_rows($nod_query)) while ($msrow=mssql_fetch_assoc($nod_query)) echo('<p>'.$msrow['Nod_Nos'].'</p>'); Quote Link to comment Share on other sites More sharing options...
Chapman Posted January 27, 2010 Author Report Share Posted January 27, 2010 (edited) man viss shis ir jauns :) to kodu vnk veidoju ar domu, ka man tas katrs ieraksts jaieraksta masīvā atbilši Id - t.i. masīva 1 elements=ar Nod_nos, kur Nod_id=1 utt, Edited January 27, 2010 by Chapman Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted January 27, 2010 Report Share Posted January 27, 2010 (edited) Atbildēšu uz jautājumu par FOR ciklu For cikls darbojās ļoti vienkārši tikai jāizprot viņu for(a=b;a<=c;d){ .. } a = mainīgais kuru lietosi skaitīšanai b = skaitlis ar kuru saksi skaitit c = skaitlis kurš būs kā pēdējais skaitlis d = skaitīt uz augšu vai uz leju, mainīgais++ vai mainīgais-- a<=c, a<c, a>c, a>=c Piemeram for($i=0;$i<5;$i++) { echo $i; } # atgriezīs 01234 for($i=0;$i<=5;$i++) { echo $i; } # atgriezīs 012345 for($i=5;$i>0;$i--) { echo $i; } # atgriezīs 54321 for($i=5;$i>=0;$i--) { echo $i; } # atgriezīs 543210 Edited January 27, 2010 by EdgarsA Quote Link to comment Share on other sites More sharing options...
Maris-S Posted January 27, 2010 Report Share Posted January 27, 2010 Ierakstīšanu masīvā varētu veidot aptuveni šādi: // Connect to MSSQL and select the database $link = mssql_connect($host, $username, $password); mssql_select_db('SecKeyPrior'); // Select all our records from a table $result=array(); $nod_query = mssql_query('SELECT Id_Nod, Nod_Nos From S_Nod'); if (is_resource($nod_query) && mssql_num_rows($nod_query)) while ($msrow=mssql_fetch_assoc($nod_query)) $result[$msrow['Id_Nod']]=$msrow['Nod_Nos']; Rakstīju uz ātro, tāpēc jāpatestē, iespējams kādas kļūdas var parādīties. Quote Link to comment Share on other sites More sharing options...
Chapman Posted January 27, 2010 Author Report Share Posted January 27, 2010 nja... lietas, ko velos tagad izveidot: no db (S_Nod) for cikla nolasit lauka Nod_nos vertibas un sarakstis masīva tad attēlot šīs vērtības izkritošajā saraksta atbilstoši Id (Id sak skaitit no 2, tātad masīvs[1] būs vienāds ar tabulas pirmo ierakstu) kā to labāk izdarīt? Quote Link to comment Share on other sites More sharing options...
eT` Posted January 27, 2010 Report Share Posted January 27, 2010 izkrītošajā sarakstā? ķipa drop-down? kā menu? nu tad ieliec JS ar dropdown un pirms for cikla ieliec tagus kādos būs menu elementi piem <ul> un pēc for cikla </ul> un cikla iekšienē kur notiek izvade <li>$msrow["Nod_Nos"]</li> Quote Link to comment Share on other sites More sharing options...
Chapman Posted January 28, 2010 Author Report Share Posted January 28, 2010 nu ta... javaskripts strada, tiek izveidoti tik izkritosha saraksta elementi, cik ir db rindas, bet man isti nesanak uztaisit Nod_Nos ierakstishanu masiva :( Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted January 28, 2010 Report Share Posted January 28, 2010 un ka lai es tagad uzminu ka tu to dari ? moš tomēr kādu koda gabalu iedosi ? Quote Link to comment Share on other sites More sharing options...
Chapman Posted January 28, 2010 Author Report Share Posted January 28, 2010 un ka lai es tagad uzminu ka tu to dari ? moš tomēr kādu koda gabalu iedosi ? <?php $link = mssql_connect($host, $username, $password); mssql_select_db('SecKeyPrior'); $nod_query = mssql_query('SELECT Id_Nod, Nod_Nos From S_Nod'); if (is_resource($nod_query) && mssql_num_rows($nod_query)) while ($msrow=mssql_fetch_assoc($nod_query)) $result[$msrow['Id_Nod']]=$msrow['Nod_Nos']; echo $result[$msrow['Id_Nod']]; $nod_skaits = mssql_num_rows($nod_query); echo $nod_skaits; <html> <head> <script type="text/javascript"> function nod() { var mylist=document.getElementById("myList"); document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text; } </script> </head> <form> Nodaļa: <select id="myList" onchange="nod()"> <?php for ( $a = 1; $a <= $nod_skaits; $a++ ) { ?> <option> <?php $msrow["Nod_Nos"] ?> </option> <?php }?> </select> <p>N: <input type="text" id="favorite" size="20"></p> </form> zinu, ka kods izskatas vnk pretigs, bet ta sir tik uzmetums :) Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted January 28, 2010 Report Share Posted January 28, 2010 tu āksties? :D 1. <?php 2. 3. $link = mssql_connect($host, $username, $password); 4. mssql_select_db('SecKeyPrior'); 5. $nod_query = mssql_query('SELECT Id_Nod, Nod_Nos From S_Nod'); 6. 7. if (is_resource($nod_query) && mssql_num_rows($nod_query)) 8. while ($msrow=mssql_fetch_assoc($nod_query)) 9. $result[$msrow['Id_Nod']]=$msrow['Nod_Nos']; 10. echo $result[$msrow['Id_Nod']]; 11. 12.$nod_skaits = mssql_num_rows($nod_query); 13.echo $nod_skaits; 14.<html> 15.<head> 16.<script type="text/javascript"> 17.function nod() 18.{ 19.var mylist=document.getElementById("myList"); 20.document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text; 21.} 22.</script> 23.</head> 24. ?!??!?!?! 25.<form> 26.Nodaļa: 27.<select id="myList" onchange="nod()"> 28.<?php 29.for ( $a = 1; $a <= $nod_skaits; $a++ ) 30.{ 31.?> 32. <option> 33. <?php $msrow["Nod_Nos"] ?> 34. </option> 35. <?php }?> 36.</select> 37.<p>N: <input type="text" id="favorite" size="20"></p> 38.</form> 5 rindinja - 'SELECT Id_Nod, Nod_Nos From S_Nod' kapec nevar vnk "select id_nod,nod_nos from s_nod" ? kapec lieki jatizlojas. 24 rindinja - kur ir body? 12 rindinja - mssql ? vai tomer mysql? 8 rinda - ieteiktu lietot mysql_fetch_array(..) nevis mssql_fetch_assoc.. 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.