knight47 Posted January 14, 2007 Share Posted January 14, 2007 Ok, so I'm working on my newest script, just for practice, i'm a begginer, and you might see that in my code. :DIn this script, I have 2 scripts, gen.php, and creator.php. www.knight47.com/rss_project . The gen.php generates html code depending on what the user has typed, then creator.php generates more code depending on the user input.The creator.php isn't really working, the problem is at the second loop, and I know i'm missing a few things, but I'm just trying to get the gist of the script.Gen.php:[code=php:0]<?phpif ($_POST['Submit']){$feedtitle = 1;$feeddisc = 1;$feedurl = 1;$code1 = "<?xml version=\"1.0\"?> <rss version=\"2.0\"> <channel> <title>{$_POST['sitename']}</title><link>{$_POST['siteurl']}</link><description>{$_POST['sitedescription']}</description> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>www.knight47.com</generator> <pubDate>{$_POST['date']}</pubDate>";while ($start < $number){echo "<item><title>{$_POST['feed$feedtitle']}</title><description>{$_POST['feeddisc$feeddisc']}</description><link>{$_POST['feedurl$feedurl']}</link><pubDate>{$_POST['date']}</pubDate></item>";$feedtitle ++;$feeddisc ++;$feedurl ++;}}?>[/code]Creator.php:[code=php:0]<?php$number = $_POST['number'];$starttwo = 0;$start = 0;$title = 1;$disc = 1;$url = 1;$feeds = $_POST['feeds'];echo "<form name=\"form1\" method=\"post\" action=\"creator.php\"><br />";echo "Items in this Feed: <label> <input name=\"feeds\" type=\"text\" id=\"feeds\" value=\"$number\"size = \"1\"/></label><br />";echo "<label> <input name=\"sitename\" type=\"text\" id=\"sitename\" size=\"35\" /> </label><br /> ";echo "<label> <input name=\"siteurl\" type=\"text\" id=\"siteurl\" value=\"http://www.\" size=\"35\" /> </label><br />";echo "<label> <input name=\"sitedescription\" type=\"text\" id=\"sitedescription\" value=\"My site has blah blah blah..\" size=\"60\" /> </label><br /><br />";while ($start < $number){echo "<label> <input type=\"text\" name=\"title$title\"> </label><br />";echo "<label> <input type=\"text\" name=\"description$disc\"> </label><br />";echo "<label> <input type=\"text\" name=\"url$url\"> </label><br /> <br />";$start ++;$title ++;$disc ++;$url ++;}echo "<label><input name=\"Submit\" type=\"submit\" value=\"Generate!\" /> </label>";if ($_POST['Submit']){$feedtitle = 1;$feeddisc = 1;$feedurl = 1;$title = $_POST['title'];echo "<?xml version=\"1.0\"?> <rss version=\"2.0\"> <channel> <title>{$_POST['sitename']}</title><link>{$_POST['siteurl']}</link><description>{$_POST['sitedescription']}</description> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>www.knight47.com</generator> <pubDate>{$_POST['date']}</pubDate>";while ($starttwo < $feeds) {echo "<item><title>{$_POST['title$feedtitle']</title><description>{$_POST['description$feeddisc']}</description><link>{$_POST['url$feedurl']}</link><pubDate>{$_POST['date']}</pubDate></item>";$starttwo ++;$feedtitle ++;$feeddisc ++;$feedurl ++; }}echo "</channel></rss>";?>[/code]What the scripts are suppose to do, is create an RSS Feed depending on what the user types in. I hope that made sense, and if it didn't please let me know. Thank you. Link to comment https://forums.phpfreaks.com/topic/34100-a-while-statment-inside-of-an-if-statement-not-really-working/ Share on other sites More sharing options...
knight47 Posted January 14, 2007 Author Share Posted January 14, 2007 to be more specific, this is the part that's not working:[code=php:0]if ($_POST['Submit']){$feedtitle = 1;$feeddisc = 1;$feedurl = 1;$title = $_POST['title'];echo "<?xml version=\"1.0\"?> <rss version=\"2.0\"> <channel> <title>{$_POST['sitename']}</title><link>{$_POST['siteurl']}</link><description>{$_POST['sitedescription']}</description> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>www.knight47.com</generator> <pubDate>{$_POST['date']}</pubDate>";while ($starttwo < $feeds) {echo "<item><title>{$_POST['title$feedtitle']</title><description>{$_POST['description$feeddisc']}</description><link>{$_POST['url$feedurl']}</link><pubDate>{$_POST['date']}</pubDate></item>";$starttwo ++;$feedtitle ++;$feeddisc ++;$feedurl ++; }}[/code] Link to comment https://forums.phpfreaks.com/topic/34100-a-while-statment-inside-of-an-if-statement-not-really-working/#findComment-160383 Share on other sites More sharing options...
kenrbnsn Posted January 14, 2007 Share Posted January 14, 2007 Please elaborate on the phrase "is not working". What is not working? Have you used any debugging techniques to determine what's going on in your script.BTW, your code would be much cleaner if you used arrays as your field names instead of what you're doing now:Gen.php[code]<?phpif ($_POST['Submit']){ $feedtitle = 1; $feeddisc = 1; $feedurl = 1; $code1 = "<?xml version=\"1.0\"?> <rss version=\"2.0\"> <channel> <title>{$_POST['sitename']}</title> <link>{$_POST['siteurl']}</link> <description>{$_POST['sitedescription']}</description> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>www.knight47.com</generator> <pubDate>{$_POST['date']}</pubDate>"; for ($start = 0;$start < $number;$start++) echo '<item><title>' . $_POST['feed'][$feedtitle++] . '</title><description>' . $_POST['feeddisc'][$feeddisc++] . '</description><link>' . $_POST['feedurl'][$feedurl++] . '</link><pubDate>' . $_POST['date'] . "</pubDate></item>"; }?>[/code]Creator.php[code]Creator.php:<?php$number = $_POST['number'];$starttwo = 0;$start = 0;$title = 1;$disc = 1;$url = 1;$feeds = $_POST['feeds'];echo '<form name="form1" method="post" action="creator.php"><br />';echo 'Items in this Feed: <label> <input name="feeds" type="text" id="feeds" value="' . $number . '" size = "1"/></label><br />';echo '<label> <input name="sitename" type="text" id="sitename" size="35" /> </label><br /> ';echo '<label> <input name="siteurl" type="text" id="siteurl" value="http://www." size="35" /> </label><br />';echo '<label> <input name="sitedescription" type="text" id="sitedescription" value="My site has blah blah blah.." size="60" /> </label><br /><br />';for ($start = 0; $start < $number; $start++){ echo '<label> <input type="text" name="title[' . $title++ . ']"> </label><br />'; echo '<label> <input type="text" name="description[' . $disc++ . ']"> </label><br />'; echo '<label> <input type="text" name="url[' . $url++ . ']"> </label><br /> <br />';}echo "<label><input name=\"Submit\" type=\"submit\" value=\"Generate!\" /> </label>";if ($_POST['Submit']){ $feedtitle = 1; $feeddisc = 1; $feedurl = 1; $title = $_POST['title']; echo "<?xml version=\"1.0\"?> <rss version=\"2.0\"> <channel> <title>{$_POST['sitename']}</title> <link>{$_POST['siteurl']}</link> <description>{$_POST['sitedescription']}</description> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>www.knight47.com</generator> <pubDate>{$_POST['date']}</pubDate>"; for ($starttwo = 0;$starttwo < $feeds;$starttwo++) echo '<item><title>' . $_POST['title'][$feedtitle++] . '</title><description>' . $_POST['description'][$feeddisc++] . '</description><link>' . $_POST['url'][$feedurl++] . '</link><pubDate>' . $_POST['date'] . "</pubDate></item>"; }echo "</channel></rss>";?>[/code]I'm not saying that the above code will help find your problems, but I think it's cleaner code. (IMHO)BTW, in Gen.php you don't initialize the $start or $number variables, so your loop won't do anything. I changed the loops from "while" loops to "for" loops.Ken Link to comment https://forums.phpfreaks.com/topic/34100-a-while-statment-inside-of-an-if-statement-not-really-working/#findComment-160528 Share on other sites More sharing options...
knight47 Posted January 14, 2007 Author Share Posted January 14, 2007 Sorry for being so unclear. What this script is suppose to do is generate RSS Feeds, you type in your Site URL, description, ect... and then you type in all the items nessesary, you hit generate and it creats an XML file (still haven't added this to the code yet). So first off, I need to know how many items to put in the rss generator, that's what the gen.php is basically for. So say they input 4, gen.php generates 4 items, each item includes the title, url, and description.So after you've inputed everything, you hit generate again, and now it will take what you've inputted, and generate it into XML.I hope that made sense ;DBut I tried your code, and it actually did work, except for the TITLE field in creator.php. Thank you so much for taking your time to do that.And also, sorry for all these Link to comment https://forums.phpfreaks.com/topic/34100-a-while-statment-inside-of-an-if-statement-not-really-working/#findComment-160650 Share on other sites More sharing options...
knight47 Posted January 14, 2007 Author Share Posted January 14, 2007 *Oops, I accidenlty hit enter, and I don't see where you can edit a post*...questions, but I'm a beginner in php, and what I know is basically looking at other scripts, and reading online, so I know very little. What are for loops, and how are they different for while loops? And what do . do, for example: description[' [b].[/b] $disc++ [b].[/b] ']Thanks so much for your time, I really appreciate it :) Link to comment https://forums.phpfreaks.com/topic/34100-a-while-statment-inside-of-an-if-statement-not-really-working/#findComment-160656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.