hal-11 Posted October 8, 2012 Share Posted October 8, 2012 Hi I am currenly doing a project where i am required to send some values to secure http via post request..I am using Curl for this and that works fine, what I am stuck on is how to retrieve stored database values and send each one individually in a loop to the specified url in the curl script. Hard to explain but heres an example: e.g I have a number of reports in db (123456, 123654, 456321) and each one will retrieve a report from the url as they are the specified report_ids required. I would like to pull each one from the database using a foreach loop assigning the report number to $reportid variable one at a time, and also when the report is retrieved with each one, fwrite it to file. I can currently get all of the above working but only if i assign the report number in the script rather than assigning it the db value and looping through each one. I suppose my question is how can i not only loop through db values but assign each id to the reportid sent via curl and then do it all over again for the next id... Any help in the right direction would be awesome.! Quote Link to comment https://forums.phpfreaks.com/topic/269222-loop-through-database-values/ Share on other sites More sharing options...
Psycho Posted October 8, 2012 Share Posted October 8, 2012 Pretty basic stuff: $query = "SELECT report_id FROM reports_table"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $reportID = $row['report_id']; //Insert code to run curl process, use $reportID as needed. Example: $curlURL = "http://www.somedomain.com/get_report?id=$reportID"; } You just need to find where the report ID is used in your current code and replace with the variable you create when iterating through the results. Quote Link to comment https://forums.phpfreaks.com/topic/269222-loop-through-database-values/#findComment-1383773 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.