KirkLogan Posted March 4, 2013 Share Posted March 4, 2013 I am unsure as to the best way to do this. I am building a query using the following loop: for($i=0;$i<count($data); $i++) { $query .= "'{$fileop[$i]}', "; } My problem is, at this point in the loop, I do NOT want $fileop to output its contents (it is not even defined yet). Rather i need $fileop to display exactly as is, so that the variable name is stored in the string rather than its value at this point in time. I do however want the value of $i to output within the brackets. I suppose what im asking is, is there a way to nullify store $fileop within a string so that I can call it later (within another loop) and have it actually reference the value when the query is called? (or maybe im just ass backwards here and should take a different approach to this whole section) Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/ Share on other sites More sharing options...
requinix Posted March 4, 2013 Share Posted March 4, 2013 Can't you just move the loop down to a point where $fileop has its values? Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416594 Share on other sites More sharing options...
KirkLogan Posted March 5, 2013 Author Share Posted March 5, 2013 I considered that but i run into problems as i will be using the query within a while loop to import .CSV file rows into a database. Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416595 Share on other sites More sharing options...
Barand Posted March 5, 2013 Share Posted March 5, 2013 perhaps <?php for($i=0;$i<count($data); $i++) { $query .= "\$fileop[$i], "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416599 Share on other sites More sharing options...
KirkLogan Posted March 5, 2013 Author Share Posted March 5, 2013 Thank you sir! That is exactly what I needed. Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416601 Share on other sites More sharing options...
requinix Posted March 5, 2013 Share Posted March 5, 2013 There's also prepared statements to consider, which would actually be perfect for this. Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416606 Share on other sites More sharing options...
KirkLogan Posted March 5, 2013 Author Share Posted March 5, 2013 Prepared statements? Do you have a good reference so i can read about this? Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416608 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 http://lmgtfy.com/?q=PHP+prepared+statements Jessica, sorry to steal your thunder. Seemed appropriate. Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416621 Share on other sites More sharing options...
requinix Posted March 5, 2013 Share Posted March 5, 2013 http://lmgtfy.com/?q=PHP+prepared+statements Jessica, sorry to steal your thunder. Seemed appropriate. Quote Link to comment https://forums.phpfreaks.com/topic/275250-help-building-a-query-string-mysql/#findComment-1416623 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.