Jump to content
php.lv forumi

mysql_fetch_array


freimanisg

Recommended Posts

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 by freimanisg
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 by freimanisg
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...