sandshakimi Posted September 13, 2014 Share Posted September 13, 2014 I'm using a web service call, my response comes back as an array: stdClass Object ( [contractVehicle] => Array ( [0] => ITSchedule70 [1] => ITCommodityProgram ) ) I then need to hand this response off to anther developer who needs to know that "ITSchedule70" is the selected Contract Vehicle (actually there could be more than one, this only returns one for now), so he can insert it into a SQL query against a MySQL database (to match "Products" with the right "Contract Vehicle". So basically how do I do that? How to wrap it up and send it off, and how to insert a query? Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/ Share on other sites More sharing options...
requinix Posted September 13, 2014 Share Posted September 13, 2014 Hand to "another developer"... how? Are you going to print it out on a piece of paper and send it to them through the mail? Or maybe hire one of those airplanes that flies around cities trailing a banner? Because you have a PHP object right now and I can't figure that's very far from what you actually need. Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/#findComment-1491014 Share on other sites More sharing options...
sandshakimi Posted September 14, 2014 Author Share Posted September 14, 2014 Sorry, I should clarify. Its my inexperience with PHP. So now I have this object, how do I use it to write PHP in a SELECT query. Specifically, using WHERE condition the contract vehicle should be ITSchedule70 in the query statement. Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/#findComment-1491015 Share on other sites More sharing options...
requinix Posted September 14, 2014 Share Posted September 14, 2014 Getting the value by itself is easy enough: $object->contractVehicle[0] // and [1]The only other thing is the query itself. How much do you have there? Is it ready except for adding in the value? Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/#findComment-1491020 Share on other sites More sharing options...
sandshakimi Posted September 14, 2014 Author Share Posted September 14, 2014 More clarification: Evertime the user submits the form, I'm making a call to the web service. So it might return 0=>'ITSchedule70' or 1=>'ITCommodityProgram' or 2=>'OtherContractVehicle' I've got 4 contract vehicles. Based on that returned contract vehicle, I need to use that as a WHERE criteria to return results from a Products table. So like: SELECT * FROM `product` WHERE `contact_vehicle_id` = 2 So the important point is the WHERE needs to be dynamic, because on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/#findComment-1491021 Share on other sites More sharing options...
requinix Posted September 14, 2014 Share Posted September 14, 2014 Well you can't magically turn "ITSchedule70" into the number 2. You need a query that uses the term "ITSchedule70" in it. Might involve a JOIN against another table (or more than one). Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/#findComment-1491023 Share on other sites More sharing options...
sandshakimi Posted September 14, 2014 Author Share Posted September 14, 2014 Well, if I use the term "ITSchedule70" in the query, that seems to defeat the whole purpose. Everytime the form is submitted, the web service call will return a different contract vehicle. "ITSchedule70" is one of many. I believe I need to pass a variable in the WHERE criteria, so the SQL query doesn't have to be written each time. Not sure, perhaps I'm thinking of this the wrong way? Or missing something fundemental? Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/#findComment-1491027 Share on other sites More sharing options...
requinix Posted September 14, 2014 Share Posted September 14, 2014 (edited) I think you are missing something. Yes, you need something variable in the query. Presumably the ITSchedule70 thing. Of course you can't write it directly in the query. But for you, just for now, write it directly in the query, okay? When all that works you can worry about using a variable or whatever. Edited September 14, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/291045-use-php-array-with-sql-query/#findComment-1491029 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.