Perigoso Posted December 15, 2009 Share Posted December 15, 2009 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 More sharing options...
cags Posted December 15, 2009 Share Posted December 15, 2009 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? Link to comment https://forums.phpfreaks.com/topic/185212-help-on-myslq_fetch_array/#findComment-977729 Share on other sites More sharing options...
Perigoso Posted December 15, 2009 Author Share Posted December 15, 2009 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 Link to comment https://forums.phpfreaks.com/topic/185212-help-on-myslq_fetch_array/#findComment-977734 Share on other sites More sharing options...
cags Posted December 15, 2009 Share Posted December 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/185212-help-on-myslq_fetch_array/#findComment-977746 Share on other sites More sharing options...
Perigoso Posted December 15, 2009 Author Share Posted December 15, 2009 What do you think if i store the values during the while in a temporary table so then i can work out the vaules?? Is it a good way to solve the issue? Link to comment https://forums.phpfreaks.com/topic/185212-help-on-myslq_fetch_array/#findComment-977942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.