Note that there are some explanatory texts on larger screens.

plurals
  1. POOrdering text file entries by letter
    primarykey
    data
    text
    <p>I am new to PHP so I'm sorry if anything I ask isn't clear. </p> <p>My goal is to take information from a simple HTML form that asks for users to fill out three text boxes, select if they are user 1 or user 2, and upload a file. I then have to store the information in a text file and display that information in the browser directly below the HTML form. The information must be ordered alphabetically by the first letter of whatever is entered in the first text box. Each entry must be on its own line.</p> <p>For example:</p> <p>Let's say Person 1 enters: Sally Mae Johnson User 1 Flowers.jpg Person 2 comes along later and enters: George Michael Johnson User 2 books.jpg</p> <p>Right now it displays in the order entered like this: Sally Mae Johnson User 1 Flowers.jpg George Michael Johnson User 2 books.jpg</p> <p>I need it to display in alphabetical order by the first letter of the first name like this: George Michael Johnson user 2 books.jpg Sally Mae Johnson User 1 Flowers.jpg</p> <p>Here's my code:</p> <pre><code>$fone = @$_POST["one"]; $ftwo = @$_POST["two"]; $fthree = @$_POST["three"]; $fselect = @$_POST["select"]; if ($_FILES) { $name = $_FILES['upload']['name']; (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/$name")); } //write to the file $values = "$fone\t"; $values .= "$ftwo\t"; $values .= "$fthree\t"; $values .= "$fselect\t"; $values .= "&lt;img src='uploads/$name' /&gt;&lt;br /&gt;"; //open and write to the file $fp = @fopen("store.txt", "a") or die("Couldn't open the file!"); $numBytes = @fwrite($fp, $values) or die ("Couldn't write values to file!"); @fclose($fp); ?&gt; &lt;form action="test_it.php" enctype="multipart/form-data" method="post"&gt; Box 1: &lt;input type="text" name="one" size="15" /&gt; Box 2: &lt;input type="text" name="two" size="15" /&gt; Box 3: &lt;input type="text" name="three" size="15" /&gt; Select One: &lt;select name="select"&gt;&lt;option value="empty"&gt;Please Select&lt;/option&gt;&lt;option value="user1"&gt;User 1&lt;/option&gt; &lt;option value="user2"&gt;User 2&lt;/option&gt; &lt;p&gt;Upload a File:&lt;/p&gt; &lt;p&gt;&lt;input type="file" name="upload" /&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="30000" /&gt; &lt;input type="submit" name="submit" value="submit" /&gt; &lt;input type="hidden" name="submitted" value="submitted" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;?php print "&lt;P&gt;Here are the users:&lt;br /&gt;"; $file = "store.txt"; if (file_exists($file)) { $file1 = fopen("store.txt" , "r"); while (!feof($file1)) { $display = fgets($file1, filesize("store.txt")); echo $display . " "; } fclose($file1); } else { echo "&lt;P&gt;Error occured! Please try again!&lt;/p&gt;"; } </code></pre> <p>Any help is greatly appreciated! Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload