Jnerocorp Posted November 29, 2009 Share Posted November 29, 2009 Ok I am making a form that the user inputs the following: URL (input type=text name=url) HEIGHT (input type=text maxchars=3 name=height) WIDTH (input type=text maxchars=3 name=width) Number (input type=text name=number) of times to display per refresh The form will be using GET and processed on the same page That field "Number" is the field that I want to set for the number of times to run foreach OR it will be the number of times to place "URL" into an arrray so if someone puts 5 it will either display URL 5 times or put "URL" in the same array 5 times please let me know if i am explaining this clear enough or not. -John Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/ Share on other sites More sharing options...
MadTechie Posted November 29, 2009 Share Posted November 29, 2009 Should be a simple loop ie for($n=0;$n<$_GET['number'];$n++){ echo $_GET['url']."<BR />/n"; }[/Number ] Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967548 Share on other sites More sharing options...
taquitosensei Posted November 29, 2009 Share Posted November 29, 2009 if(isset($_POST['number']) && is_int($_POST['number'])); { for($a=0;$a<$number$a++) { // do whatever in your loop } } Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967550 Share on other sites More sharing options...
Jnerocorp Posted November 29, 2009 Author Share Posted November 29, 2009 Ok Neither of those codes are working i am not getting errors though the url i tested it with is this: http://jnerocorp.com/for.php?url=http://google.com&?number=2 this is the Code I am using <?php if(isset($_GET['number']) && is_int($_GET['number'])) { $number = $_GET['number']; $url = $_GET['url']; for ($i = 0; $i < $number; $i++) { echo "$url <br>"; } } ?> -john Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967565 Share on other sites More sharing options...
MadTechie Posted November 29, 2009 Share Posted November 29, 2009 works fine if the URL was correct http://jnerocorp.com/for.php?url=http://google.com&number=2 Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967568 Share on other sites More sharing options...
Jnerocorp Posted November 29, 2009 Author Share Posted November 29, 2009 ohh that makes sense thanks guys -John Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967570 Share on other sites More sharing options...
MadTechie Posted November 29, 2009 Share Posted November 29, 2009 Can you please click topic solved Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967571 Share on other sites More sharing options...
mrMarcus Posted November 29, 2009 Share Posted November 29, 2009 is_int() will return false when checking strings (values in URL are strings). use is_numeric() or ctype_digit() instead. how are you getting it to work with is_int()? Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967572 Share on other sites More sharing options...
mrMarcus Posted November 29, 2009 Share Posted November 29, 2009 is this the code you are currently using, exactly as seen below: <?php if(isset($_GET['number']) && is_int($_GET['number'])) { $number = $_GET['number']; $url = $_GET['url']; for ($i = 0; $i < $number; $i++) { echo "$url <br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967579 Share on other sites More sharing options...
salathe Posted November 29, 2009 Share Posted November 29, 2009 You could also use the array_fill function to create an array of however many of the URLs you want. $urls = array_fill(0, $_GET['number'], $_GET['url']); Link to comment https://forums.phpfreaks.com/topic/183304-changing-the-number-of-times-to-run-foreach/#findComment-967581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.