betaElk Posted October 4, 2006 Share Posted October 4, 2006 hi, this is my first script and ive had success with it so far but now i want to adapt it, it prints off an ordered list and i would like to controll the numbers in the ordered list with php:[code]<?php$filename = "capformtest.txt"; $nameid = 1;while ($nameid < 99){if (isset($_POST['submit'])) { //if no name entered print an error if (empty($name)) { $noname = "Inget namn gav"; } else { $file = fopen( $filename, "a"); $string = "<li value=\"$nameid\">$name</li>"; fwrite( $file, $string ); $nameid = $nameid + 1; if (!empty($thecomment)) { $string = "<ol><li>$thecomment</li></ol>"; fwrite( $file, $string ); } fclose( $file ); } }}?>[/code]So basically what im trying to do is start the ordered list at one and count up (I used < 99 just as a random number, there definatly wont be more than 99 entries...) but i tested it and scince i added the WHILE loop its just stopped the page from loading.Any advice on another way to do it would be great! Quote Link to comment Share on other sites More sharing options...
thepip3r Posted October 4, 2006 Share Posted October 4, 2006 if you're using an ordered list, you can't control the numbering sequence; the number just increments from 1 every time an <ol> tag is called. if you want to create your own numbering system, you're off to a quasi-OK start. Remove your while statement altogether. You will definately need a loop but the loop you need is to read each line of the file you've opened. Look at the fopen() function on how to loop through each line in a file. Once you start doing that, just echo $nameid in your loop and increment the number using $nameid++; That will increment the number for each iteration of your loop... Quote Link to comment 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.