Jump to content

Tryin WHILE with an ordered list


betaElk

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.