knight47 Posted November 29, 2006 Share Posted November 29, 2006 Sorry for the lame title, but I don't really know how to explain this...I created a simple 5 item rss feed generator which can be viewed at knight47.com/rss , it's very simple, the code for the script can also be viewed, and downloaded.Anyways, if you notice, the script only allows 5 items, I know I can make it more, but how would I have it so that the user can specify exactly how many items he needs to be generated in the final xml file?I was thinking of having the script first ask the user how many items he needs, then according to his answer, I could direct the user to a different page, for example, if the user enters 6, it would take him to rss6.html, that with it's own custom code. If the user wants 12 feeds, it would take him to rss12.html, but that would be too much work, and I'm hoping there is a shorter way of accomplishing this.I hope my explanation made sense. Thanks! Link to comment https://forums.phpfreaks.com/topic/28822-workaround/ Share on other sites More sharing options...
knight47 Posted November 29, 2006 Author Share Posted November 29, 2006 Sorry for the double post, but I've been thinking about it, and I think a loop would help, but I'm still a little shady on this.Ok so say the field is called numwould the code be something like[code=php:0]$num = $_POST['num'];while $num < 100 // if 100 is the max number{echo $code;$num -- // decreases the number by one every time}if $num == 0{echo " "; // just to stop the loop}[/code]But I don't think this would work, because $code needs to change for every number, lol i know i'm a horrible explainer, [url=http://www.knight47.com/php_scripts/codes.php?showcode=rss]but check the code[/url], it might make more sense than me. Because how would this modify the html code too?? I would need more text fields each with different input names. I hope that made sense. Link to comment https://forums.phpfreaks.com/topic/28822-workaround/#findComment-131952 Share on other sites More sharing options...
knight47 Posted November 29, 2006 Author Share Posted November 29, 2006 does anyone know? Link to comment https://forums.phpfreaks.com/topic/28822-workaround/#findComment-132451 Share on other sites More sharing options...
Psycho Posted November 30, 2006 Share Posted November 30, 2006 [code]<?php$num = $_POST['num'];for ($item =1; $item < $num; $item++) {echo $code;}?>[/code]Your code above would work (if it was written correctly), but I think this is a little more efficient. There are problems with your code, however. The logic is backwards. The way it is written the loop would continue as long as $num is less than 0. Since you are subtracting 1 from $num each time through it would always be less than 100 (as long as it started as less than 100). It needs to run as long as $num is greater than 0. Also, the last piece within the curly brackets is not needed. The loop will exit on it's own once the condition is false. Should be more like this:[code]<?php$num = $_POST['num'];while ($num > 0 ){echo $code;$num -- // decreases the number by one every time}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28822-workaround/#findComment-132464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.