Jump to content

Loop Through Database Values


hal-11

Recommended Posts

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.!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.