solon Posted December 19, 2008 Share Posted December 19, 2008 Hey guys, I have a variable that is within a while loop: i.e: while($row = mysql_fetch_array($result) { $var = $row[some_value]; } if ... { if { ... } ... } $var // i need to use the variable somewhere here but i still get it as empty ('') I need that variable ($var) to work outside of the loop... is there a way to do that? Any help would be great... Link to comment https://forums.phpfreaks.com/topic/137664-solved-variable-problem/ Share on other sites More sharing options...
Adam Posted December 19, 2008 Share Posted December 19, 2008 Can you explain it a little more clearly? Do you mean to kinda 'unset' $var after the loop for re-use? .. or do you mean to carry the data out of the loop, for use later on? A Link to comment https://forums.phpfreaks.com/topic/137664-solved-variable-problem/#findComment-719504 Share on other sites More sharing options...
suma237 Posted December 19, 2008 Share Posted December 19, 2008 $row = mysql_fetch_array($result) @extract($row); print $feildname; ..$fieldname should be your column name of the table Link to comment https://forums.phpfreaks.com/topic/137664-solved-variable-problem/#findComment-719513 Share on other sites More sharing options...
Adam Posted December 19, 2008 Share Posted December 19, 2008 Sorry I misread your question slightly before... Can you post your actual code? Also how many rows are pulled from that database (roughly)? Just that $var is going to be overwritten every time your 'while' makes a loop and it could just be that the last record returned is simply empty! A Link to comment https://forums.phpfreaks.com/topic/137664-solved-variable-problem/#findComment-719518 Share on other sites More sharing options...
solon Posted December 19, 2008 Author Share Posted December 19, 2008 Guys thanks for the responses but i solved it! the question was for carrying the value for later use but actually i didn't have to do anything, as it seems the value is being carried . I could not see it before cause i had an error in my sql query! Sorry for that.. and thanks again Link to comment https://forums.phpfreaks.com/topic/137664-solved-variable-problem/#findComment-719542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.