jakebur01 Posted April 7, 2009 Share Posted April 7, 2009 How could I redirect to myself and use Get to pass the last ID limiting 25 each time? example..... run 25 then redirect to: mypage.php?offset=25 run 25 more then redirect to mypage.php?offset=50 and so on.. $total_rows = mysql_num_rows(mysql_query("SELECT * FROM zip_code where `state_prefix` = 'OK'", $db)); $rows_per_loop = 20; $total_loops = ceil($total_rows/$rows_per_loop); // run the loop, while loop counter is less than the total number of loops: for($s=0; $s<$total_loops; $s++) { // get the numbers for the limit, // start is just the current loop number multiplied by the rows per loop // and end is loop counter + 1, multiplied by the rows per loop $limit_start = $rows_per_loop*$s; $limit_end = $rows_per_loop*($s+1); $result = mysql_query("SELECT * FROM zip_code where `state_prefix` = 'OK' LIMIT $limit_start, $limit_end") or die(mysql_error()); while($myrow = mysql_fetch_array ($result)) { $zip=$myrow['zip_code']; // get DOM from URL or file $html=file_get_html("http://www.mysite.com/age.asp?transaction=search&template=map_search&search1=0&pwidth=400&pheight=700&proxIconId=400&proxIcons=1&search2=0&search3=1&country=US&searchQuantifier=AND&address=&city=&stateProvince=+&postalCode=$zip&radius=500&x=78&y=16"); $i = 0; $tmp = $html->find('span[class=mqEmp], span[class=Black11]'); $cnt = count($tmp) - 1; foreach($tmp as $e) { if($i > 0 && $i < $cnt){ $outputstring=$e->plaintext; $outputstring=$outputstring. "\t"; fwrite($fp, $outputstring, strlen($outputstring)); if ($i % 8 == 0) { fwrite($fp, $other, strlen($other)); } } $i++; } } // now that we've run those, let's clear the results so that we don't run out of memory. mysql_free_result($result); // show where we are at echo $limit_start,' - ',$limit_end,'<br />'; sleep(1); // give PHP a little nap to keep from overloading server ob_flush(); // as recommended by MadTechie, in case we go beyond the max execution time flush(); // add flush, to make sure it is outputted } fclose($fp); Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/ Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 Look up MySQL's LIMIT LIMIT x,y start at offset x then show y number of records from there. SELECT * FROM table WHERE condition LIMIT x,y Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803388 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 That's kind of what I already have going. Now I am trying to go to a new page after processing 25 rows and pick up where I left off using $_GET. Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803414 Share on other sites More sharing options...
Fruct0se Posted April 7, 2009 Share Posted April 7, 2009 So when you count to 25 redirect like: header('Refresh: 'yoursite.com/yourscript.php?'.$count); Then when the page reloads offset your SQL query by using OFFSET $_GET['count'] Hope that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803430 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 I tried this, but it is not functioning right. It is looping through and sending multiple headers without executing it. I added this at the top. if (isset($_GET['limit_start'])) { $limit_start=$_GET['limit_start']; $limit_end=$_GET['limit_end']; } And this at the bottom // now that we've run those, let's clear the results so that we don't run out of memory. mysql_free_result($result); // show where we are at echo $limit_start,' - ',$limit_end,'<br />'; sleep(1); // give PHP a little nap to keep from overloading server ob_flush(); // as recommended by MadTechie, in case we go beyond the max execution time flush(); // add flush, to make sure it is outputted header( "location:http://www.mysite/example.php?limit_start=$limit_start&limit_end=$limit_end" ); } fclose($fp); Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803537 Share on other sites More sharing options...
Fruct0se Posted April 7, 2009 Share Posted April 7, 2009 You want to make sure that the header is not updated until you finish with your SQL, I cannot tell what is going on in your code with what you provided here. Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803549 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 <?php if (isset($_GET['limit_start'])) { $limit_start=$_GET['limit_start']; $limit_end=$_GET['limit_end']; } ini_set('max_execution_time', '999'); // example of how to use basic selector to retrieve HTML contents include('simple_html_dom.php'); $source_file = "C:/Inetpub/Websites/edit.com/echo.txt"; $fp= fopen("$source_file", "a"); $other="\n"; $db = mysql_connect('localhost', 'xx', 'xx') or die(mysql_error()); mysql_select_db('xx') or die(mysql_error()); $total_rows = mysql_num_rows(mysql_query("SELECT * FROM zip_code where `state_prefix` = 'OK'", $db)); $rows_per_loop = 25; $total_loops = ceil($total_rows/$rows_per_loop); // run the loop, while loop counter is less than the total number of loops: for($s=0; $s<$total_loops; $s++) { // get the numbers for the limit, // start is just the current loop number multiplied by the rows per loop // and end is loop counter + 1, multiplied by the rows per loop $limit_start = $rows_per_loop*$s; $limit_end = $rows_per_loop*($s+1); $result = mysql_query("SELECT * FROM zip_code where `state_prefix` = 'OK' LIMIT $limit_start, $limit_end") or die(mysql_error()); while($myrow = mysql_fetch_array ($result)) { $zip=$myrow['zip_code']; // get DOM from URL or file $html=file_get_html("http://www.www.edit.com/selector.php?transaction=search&template=map_search&search1=0&pwidth=400&pheight=700&proxIconId=400&proxIcons=1&search2=0&search3=1&country=US&searchQuantifier=AND&address=&city=&stateProvince=+&postalCode=$zip&radius=500&x=78&y=16"); $i = 0; $tmp = $html->find('span[class=mqEmp], span[class=Black11]'); $cnt = count($tmp) - 1; foreach($tmp as $e) { if($i > 0 && $i < $cnt){ $outputstring=$e->plaintext; $outputstring=$outputstring. "\t"; fwrite($fp, $outputstring, strlen($outputstring)); if ($i % 8 == 0) { fwrite($fp, $other, strlen($other)); } } $i++; } } // now that we've run those, let's clear the results so that we don't run out of memory. mysql_free_result($result); // show where we are at echo $limit_start,' - ',$limit_end,'<br />'; sleep(1); // give PHP a little nap to keep from overloading server ob_flush(); // as recommended by MadTechie, in case we go beyond the max execution time flush(); // add flush, to make sure it is outputted header( "location:http://www.edit.com/selector.php?limit_start=$limit_start&limit_end=$limit_end" ); } fclose($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803554 Share on other sites More sharing options...
Fruct0se Posted April 7, 2009 Share Posted April 7, 2009 It is a bit confusing.... are you sure $html=file_get_html("http://www.www.edit.com is correct? you have www.www?? Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803563 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 dude... I edited it so everybody wouldn't see exactly all of my business. 1. I am just trying to run 25 rows. 2. Pass where I am at to the next page using $_GET and run the next set of 25 rows. 3. and continue until finished Quote Link to comment https://forums.phpfreaks.com/topic/152972-solved-use-get-to-pass-the-last-id/#findComment-803569 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.