HelpMe100 Posted July 6, 2007 Share Posted July 6, 2007 Please help me with this problem. I've got a class with an array in it, and some data in the array. I instantiate the class as myArray class, and pass it to a function, the function uses the array in the class as input for a mysql database. The problem is the sql wont input the data. I can insert into the database via sql local variables and local arrays and class variables but not class arrays? if i save the class array to a local variable and insert that into the sql then that works, but it wont go straight in? I imagine this has to do with passing the array by refrence rather than by value as i get "array[]" as the value in the database but i can't be sure. pseudo code: class arrayclass() { var options; options[0]="foo"; } Function insertData(myArray) { //THIS WORKS echo myArray->options[0]; //BUT THIS DOESN'T mysql_query("UPDATE OPTIONS SET bar='myArray->options[0]' WHERE EVER "); } myArray = new arrayClass(); insertdata(myArray); Please help. Quote Link to comment Share on other sites More sharing options...
melvincr Posted July 6, 2007 Share Posted July 6, 2007 i think it's the definition of the variable.. class arrayclass() { public $options = array(); $this->options[0] = "hurga"; } ... Quote Link to comment Share on other sites More sharing options...
HelpMe100 Posted July 6, 2007 Author Share Posted July 6, 2007 Its not that. Quote Link to comment Share on other sites More sharing options...
HelpMe100 Posted July 6, 2007 Author Share Posted July 6, 2007 bump Quote Link to comment Share on other sites More sharing options...
jscix Posted July 6, 2007 Share Posted July 6, 2007 what string is it outputting to the sql server? try: $tehstring = (myArray->options[0]); mysql_query("UPDATE OPTIONS SET bar='" . $tehstring . "' WHERE EVER ") or die("Error: " . mysql_error()); Quote Link to comment Share on other sites More sharing options...
HelpMe100 Posted July 6, 2007 Author Share Posted July 6, 2007 I've done that already and it works but i dont want to have to save all my class variables into local variables to put them into the database. The value it gives when going straight in is array[]. Quote Link to comment Share on other sites More sharing options...
HelpMe100 Posted July 7, 2007 Author Share Posted July 7, 2007 anyone? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.