XJTRy Posted March 9, 2009 Share Posted March 9, 2009 Newb. Trying to execute a for loop to update values in an array. I'm getting an "unexpected T_FOR" error. $data = mysql_query("SELECT worth FROM onlinegm"); $info = mysql_fetch_row($data); $dataArray = array () for ($var =0; $var<$info.length(); $var i++){ $dataArray[]=$info[$var]; } Link to comment https://forums.phpfreaks.com/topic/148553-solved-for-loop-and-array/ Share on other sites More sharing options...
.josh Posted March 9, 2009 Share Posted March 9, 2009 close...looks like you're mixing up some JS style coding in there. $data = mysql_query("SELECT worth FROM onlinegm"); $info = mysql_fetch_row($data); $dataArray = array (); for ($var =0; $var< count($info)-1; $var++){ $dataArray[]=$info[$var]; } Link to comment https://forums.phpfreaks.com/topic/148553-solved-for-loop-and-array/#findComment-780078 Share on other sites More sharing options...
XJTRy Posted March 9, 2009 Author Share Posted March 9, 2009 Thanks Crayon. Yeah, I'm an actionscript guy. Baby steps.... Link to comment https://forums.phpfreaks.com/topic/148553-solved-for-loop-and-array/#findComment-780086 Share on other sites More sharing options...
.josh Posted March 9, 2009 Share Posted March 9, 2009 Main thing to remember is that php doesn't have the OOP syntax for things like var.length etc... instead it has predefined functions that you pass arguments to (the variable/array name, etc...). That's why despite the fact that you can make custom objects/classes/interfaces/properties/methods etc.. a lot of people don't feel php is truly an OOP language. Link to comment https://forums.phpfreaks.com/topic/148553-solved-for-loop-and-array/#findComment-780089 Share on other sites More sharing options...
XJTRy Posted March 9, 2009 Author Share Posted March 9, 2009 Understood. I actually thought that the mysql_fetch_row($data) would return an array. Is that not correct? There are only 2 rows. The worth values are 25 and 35. I can update a field by setting it = '$data[0]' which enters 25. but setting it = '$data[1]' enters 0. $data = mysql_query("SELECT worth FROM onlinegm"); $info = mysql_fetch_row($data); if ($destination == ""){ } else { $query = "UPDATE gmData SET possible = '$info[1]' WHERE user = '$user'"; $result = mysql_query($query) or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/148553-solved-for-loop-and-array/#findComment-780095 Share on other sites More sharing options...
.josh Posted March 9, 2009 Share Posted March 9, 2009 Nah...not that hard to understand, but it's a little more complicated than that...this tutorial explains basic database interaction. The concept, how to do it, etc... Link to comment https://forums.phpfreaks.com/topic/148553-solved-for-loop-and-array/#findComment-780109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.