While parsing xml/json, skip page if error message received

ShareFive

New Member
I have following issue. I am parsing an xml feed with multiple pages and there is no way to understand how many they are (I have a variavle set in the xml url, so for each variable there are random number of pages). All I know is that the number can not exceed 50. Now I have a script that autoincrement the variable for the page number starting at 1 and up to 50.Let's say, that the link has total of 26 pages. With my script I will continue to send requests until the scripts gets to page 50. Than it changes the first variable and starts again from 1 to 50. For the first link, from page 27 forward the xml will return followwing:\[code\]<response> <status>error</status> <code>400</code> <message>Incorrect Request Headers</message></response>\[/code\]How can I make so when the scipt receive this message, to stop the autoincrement and continue by changing the first variable and start again at 1? The code now is:\[code\]$query = "SELECT * FROM table_name ORDER BY id ASC";$result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { if($row['row_name'] == '') { $variable1 = 0; } else { $variable1 = $row['row_name']; }$page = 0; do { $page++; $result = apiCall('option1', 'option2', array('option3' => $variable1, 'page' => $page)); usleep(1000); $res = json_decode($result); foreach ($res->node1->node2 as $item) { //define variable for insertion in MySQL $sql1 to insert the variables if (!mysql_query($sql1,$con1)) { die('Error: ' . mysql_error()); } } } while ($page<=50);}\[/code\]In the above code, only the \[code\]$variable1\[/code\] and \[code\]$page\[/code\] are variables. All options (1, 2 and 3) are predefined and stay the same. I.e. I need when the script gets the error message to start again from 1 with next value of \[code\]$variable1\[/code\].
 
Back
Top