Need help with php programming?

Here is the code provided by the teacher. (mrvaughan.com)
<html>
<head></head>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input name="crush" size="30">
<input type="hidden" name="all" value="<?php echo $_POST['crush']."<br>".$_POST['all'] ;?>" size="30">
<input type="submit" name="submit" value="add">
</form>
<?php echo $_POST['crush']."<br>".$_POST['all'];//}
?>
</body>
</html>

What it does is it creates a field to enter your word into and when you click "add" it puts it into a list below. I need to explode the list created into an array, sort it then display it on the screen. Please someone try it. I DID NOT CREATE THIS CODE I AM NOT CRAZY :) (WAMP SERVER)

Thank you

haha. This answerer above looks like he knows the correct way, heres another in case you don’t understand. I took out the hidden text field. This will come in handy too once you learn sessions.

you can use session variable for this. A session variable keeps the value of any parameter you send it throughout the duration of the session between the client and the server side script. So, you can keep a counter variable to index the list.

The first conditional will execute once since the first time you visit the page, the POST variable will be null(check the null terminator, it may be wrong. Im a j2ee koder). Afterwards you can keep incrementing the counter parameter in the SESSION variable to get the proper index for the list you are saving the values of the input field in the HTML and continue to use the list and array.

I can’t remember what explode does. I think it places list values into an array. after you do explode(), echo the array!
Most the work is done. You may have to check into lists in php. GL.

<?php
if($_POST['crush'] == ‘/0′)
{
session_start();
$_SESSION['counter'] = 0;
$a = array();
$list = list();
}
else
{
$_SESSION['counter']++;
$count = $_SESSION['counter'];
$list[$count] = $_POST['crush'];
$a = explode($list);
sort($a);
echo $a;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input name="crush" size="30">
<input type="submit" name="submit" value="add">
</form>
</body>
</html>

2 Responses to “Need help with php programming?”

  • Mantruzza says:

    <?
    print_r (sort(explode("<br>",$_POST['all'])));
    ?>

    that’s it
    References :
    experience

  • Blackcompe says:

    haha. This answerer above looks like he knows the correct way, heres another in case you don’t understand. I took out the hidden text field. This will come in handy too once you learn sessions.

    you can use session variable for this. A session variable keeps the value of any parameter you send it throughout the duration of the session between the client and the server side script. So, you can keep a counter variable to index the list.

    The first conditional will execute once since the first time you visit the page, the POST variable will be null(check the null terminator, it may be wrong. Im a j2ee koder). Afterwards you can keep incrementing the counter parameter in the SESSION variable to get the proper index for the list you are saving the values of the input field in the HTML and continue to use the list and array.

    I can’t remember what explode does. I think it places list values into an array. after you do explode(), echo the array!
    Most the work is done. You may have to check into lists in php. GL.

    <?php
    if($_POST['crush'] == ‘/0′)
    {
    session_start();
    $_SESSION['counter'] = 0;
    $a = array();
    $list = list();
    }
    else
    {
    $_SESSION['counter']++;
    $count = $_SESSION['counter'];
    $list[$count] = $_POST['crush'];
    $a = explode($list);
    sort($a);
    echo $a;
    }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input name="crush" size="30">
    <input type="submit" name="submit" value="add">
    </form>
    </body>
    </html>
    References :

Leave a Reply