Jump to content

Archived

This topic is now archived and is closed to further replies.

betaElk

Tryin WHILE with an ordered list

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.