Jump to content


Photo

Tryin WHILE with an ordered list


  • Please log in to reply
1 reply to this topic

#1 betaElk

betaElk
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 04 October 2006 - 03:51 PM

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:

<?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 );
	 }  
	 }
}

?>

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!

#2 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 04 October 2006 - 05:17 PM

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...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users