CodeMama Posted June 29, 2009 Share Posted June 29, 2009 Hi all, I need some help getting my array syntax right I'm trying to gather each piece of the array and put it in a db, the regex portion works, but something in my FOR statement is giving me the blank page of frustration: Here is my script so far: /* get_content will retrieve the contents of a web page at the supplied $url */ function get_content($url) { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, 0); ob_start(); curl_exec ($ch); curl_close ($ch); $string = ob_get_contents(); ob_end_clean(); return $string; } //first get content right //build url with date range //build a regex? to find the date from the now() command? $date = getdate(); //problem start and end dates in the url will be the same therefore only returning that days inspection. /* $start_day = $date(mday); $start_month =$date(wday); $start_year = $date(year); $end_day = $date(mday); $end_month =$date(wday); $end_year = $date(year); */ //to use for testing purposes $start_day = "1"; $start_month = "03"; $start_year = "2009"; $end_day = "07"; $end_month = "03"; $end_year = "2009"; $url = get_content ("http://www.springfieldmo.gov/health/database/foodinspections/index.jsp?st_nmbr=&start_month=$start_month¤t_name=&Submit=Search&st_name=&end_day=$end_day&end_month=$end_month&end_year=$end_year&str_loc=none&start_year=$start_year&start_day=$start_day&st_pfx=none&offset=0"); preg_match_all('/<p><font size="2" face="Arial, Helvetica, sans-serif">(.+)<br>(.+)<br>.+(\d+\/\d+\/\d+)\s(.+)<br>(.+)<br>.+Critical Violations Found:.+(\d+)(.+)Noncritical Violations Found:.+(\d+)/imsSU', $content, $results); //echo results just prints "array" to screen echo $results; for ($i=0; $i < count($results[0]); $i++) { $name = $results[1][$i]; $address = $results[2][$i]; $inDate = $results[3][$i]; $inType = $results[4][$i]; $notes = $results[5][$i]; $critical = $results[6][$i]; $cviolations = $results[7][$i]; $noncritical = $results[8][$i]; $ncviolations = $results[9][$i]; }; echo $name[$i]; /* $sql = "INSERT INTO `restuarants` (name, address, inDate, inType, notes, critical, cviolations, noncritical, ncviolations) VALUES ("; $sql .= " '$name', '$address', '$inDate', '$inType', '$notes', '$critical', '$nviolations', '$noncritical', '$ncviolations')"; mysql_query($sql); */ ?> Link to comment https://forums.phpfreaks.com/topic/164086-solved-dealing-with-arrays-to-database/ Share on other sites More sharing options...
dzelenika Posted June 29, 2009 Share Posted June 29, 2009 Why don't you put INSERT in for loop? And what means $name[$i] out of the for loop? BTW $name is not an array. Link to comment https://forums.phpfreaks.com/topic/164086-solved-dealing-with-arrays-to-database/#findComment-865576 Share on other sites More sharing options...
CodeMama Posted June 29, 2009 Author Share Posted June 29, 2009 You mean move it up into the "for" loop? I haven't actually started trying to insert anything --but when I do I will move it up into the loop, first i want to try and get it to print the array variables ($name etc) to the screen, and I haven't got that part to work yet ... Link to comment https://forums.phpfreaks.com/topic/164086-solved-dealing-with-arrays-to-database/#findComment-865577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.