Jump to content

Help on myslq_fetch_array


Perigoso

Recommended Posts

Hi everyone.

I got a problem and i've been trying to solve but with no sucess.

 

here it is:

 

$query2 = "SELECT distinct codigo FROM producao where material IN('BMF','Broca') and data BETWEEN '$di' AND '$df'";

$resultado2 = mysql_query($query2) or die(mysql_error());

while($row2 = mysql_fetch_array($resultado2)){
//echo "$row2[0] <BR>";

$query3 = "SELECT nome,pesoentrada FROM fornecedores where id=$row2[0]";
$resultado3 = mysql_query($query3) or die(mysql_error());

while($array = mysql_fetch_array($resultado3)){
//echo "$array[0]  - $array[1] <BR>";


}
}

The problem is that i need to use the values of $array[0]  and $array[1] outside of the while cycle, and i'm not able to do it.

 

if i take out the // from the echo it will give me something like

Porche - 1250

Ferrari - 2500

Dodge - 2650

 

can anyone help me out?

Link to comment
https://forums.phpfreaks.com/topic/185212-help-on-myslq_fetch_array/
Share on other sites

You're going have to be more descriptive of your actually problem. Since you are using the while syntax to loop through the array this indicates that there is more than one value of $array[0] and $array[1] so if you wish to use them outside the loop, which iteration of the loop do you wish to have the values from?

Thanks for the reply.

I want to use every value of $array[0] and $array[1].

i have to make operations like 1250+2500+2650, but outside the last while.

The ideia is to use all the values of $array[0] and [1], of every iteration.

 

Can u understand it ?

 

I hope so.

 

Thanks

If you wish to use the values outside of the while loop, then use the while loop to add them to an array. But since you will then have an array of information, chances are your going to require a loop of some kind to perform the actions you require. Generally nine times out of ten this means you may have well just done the processing as part of the while loop.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.