freimanisg Posted December 11, 2010 Report Share Posted December 11, 2010 (edited) Vai ir pieļaujama šāda koda struktūra (mysql_fetch_array-ā vēl viens mysql_fetch_array no vienas un tās pašās tabulas)? $piepr = mysql_query("SELECT * ...... while($rinda = mysql_fetch_array($piepr)){ extract($rinda); echo blablabla... .... $piepr2 = mysql_query("SELECT *... while($rinda2 = mysql_fetch_array($piepr2)){ extract($rinda2); echo blablabla... .... } } Es šo palaidu, bet otrajā extractā tas neko neextrakto. pat nemaz otrs WHILE nenostrādā... :( Edited December 11, 2010 by freimanisg Quote Link to comment Share on other sites More sharing options...
freimanisg Posted December 11, 2010 Author Report Share Posted December 11, 2010 atbildu pats sev - jā, strādā. bija maza sintaktiska kļūdiņa (kā vienmēr...) :) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted December 11, 2010 Report Share Posted December 11, 2010 Domāju, ka jā. Patestēju - jā. =) SQL: CREATE TABLE `data` ( `name` varchar( 255 ) NOT NULL, `value` varchar( 255 ) NOT NULL, PRIMARY KEY ( `name` ) ); INSERT INTO `data` ( `name`, `value` ) VALUES ('red', 'sarkans'), ('green', 'zaļš'), ('blue', 'zils'); INSERT INTO `data` ( `name`, `value` ) VALUES ('white', 'balts'), ('black', 'melns'); PHP: <?php error_reporting( E_ALL | E_STRICT ); mb_internal_encoding( 'UTF-8' ); header( 'Content-Type: Text/HTML; Charset=UTF-8' ); mysql_connect( 'localhost', 'root', '' ) or exit; mysql_select_db( 'foo' ) or exit; $query = mysql_query(" SELECT `name`, `value` FROM `data` LIMIT 0, 3 ") or exit; while( $database = mysql_fetch_array( $query ) ) { echo "{$database['name']} => {$database['value']}" . '<br />'; } echo '<br /><br />'; $query = mysql_query(" SELECT `name`, `value` FROM `data` LIMIT 3, 4 ") or exit; while( $database = mysql_fetch_array( $query ) ) { echo "{$database['name']} => {$database['value']}" . '<br />'; } P.S. Izmanto " "... =P Quote Link to comment Share on other sites More sharing options...
Kemito Posted December 11, 2010 Report Share Posted December 11, 2010 (edited) Lūdzu nākošo reizi izmanto [code][/ code] tagus. Edited December 11, 2010 by Kemito Quote Link to comment Share on other sites More sharing options...
freimanisg Posted December 11, 2010 Author Report Share Posted December 11, 2010 (edited) Ne tā domāju, kā Tu uzrakstīji. Es biju nodomājis vēl vienu WHILE ciklu ar vēl vienu mysql_fetch_array/extract iekš jau esoša WHILE cikla. Tev ir 2 atsevišķi WHILE viens pēc otra... iečeko manu piemēru augstāk rūpīgāk. Paldies, par CODE sapratu... =) Domāju, ka jā. Patestēju - jā. =) SQL: CREATE TABLE `data` ( `name` varchar( 255 ) NOT NULL, `value` varchar( 255 ) NOT NULL, PRIMARY KEY ( `name` ) ); INSERT INTO `data` ( `name`, `value` ) VALUES ('red', 'sarkans'), ('green', 'zaļš'), ('blue', 'zils'); INSERT INTO `data` ( `name`, `value` ) VALUES ('white', 'balts'), ('black', 'melns'); PHP: <?php error_reporting( E_ALL | E_STRICT ); mb_internal_encoding( 'UTF-8' ); header( 'Content-Type: Text/HTML; Charset=UTF-8' ); mysql_connect( 'localhost', 'root', '' ) or exit; mysql_select_db( 'foo' ) or exit; $query = mysql_query(" SELECT `name`, `value` FROM `data` LIMIT 0, 3 ") or exit; while( $database = mysql_fetch_array( $query ) ) { echo "{$database['name']} => {$database['value']}" . '<br />'; } echo '<br /><br />'; $query = mysql_query(" SELECT `name`, `value` FROM `data` LIMIT 3, 4 ") or exit; while( $database = mysql_fetch_array( $query ) ) { echo "{$database['name']} => {$database['value']}" . '<br />'; } P.S. Izmanto " "... =P Edited December 11, 2010 by freimanisg Quote Link to comment Share on other sites More sharing options...
daGrevis Posted December 11, 2010 Report Share Posted December 11, 2010 Nu jā, neieskatījos. Tā arī var! =) Quote Link to comment Share on other sites More sharing options...
briedis Posted December 11, 2010 Report Share Posted December 11, 2010 nez, diezgan greiza konstrukcija. Domājams, ka te var iztikt ar JOIN'u. Es arī ieteiktu darboties bez extract funkcijas, citādi vide tiek piesārņota ar nezināmiem mainīgajiem, un uzturēt šādu kodu būtu sviests. 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.