php a-z sort using explode PLEASE NEED HELP!
Posted: Sun Jan 02, 2011 12:41 pm
Hi,I am trying to get a horizontal list of values from a php file into a select list within a form and order them a-z in the dropdown list.
The php file looks like this:
catid,category,catid,category, etc etc
In otherwords: 1111,fruit,1112,veg, etc etc
I am exploding this data into a variable called $load and I have managed to get the values to appear in a list for selection but can not seem to order them by a-z. With each cat name their is a cat id, so this would have to be ordered too. So the id stays with the correct cat name.
Can anyone assist in getting my coding to accomplish this please.
The following code is what I have so far and it shows a dropdown box with the cat name values and the value to pass on is the cat id.
Any help would be totally amazing. thanks in advance!
The php file looks like this:
catid,category,catid,category, etc etc
In otherwords: 1111,fruit,1112,veg, etc etc
I am exploding this data into a variable called $load and I have managed to get the values to appear in a list for selection but can not seem to order them by a-z. With each cat name their is a cat id, so this would have to be ordered too. So the id stays with the correct cat name.
Can anyone assist in getting my coding to accomplish this please.
The following code is what I have so far and it shows a dropdown box with the cat name values and the value to pass on is the cat id.
Code: Select all
<form action="<? echo $_SERVER['PHP_SELF']; ?>?sessionid=<?php echo $sessionid; ?>" method="POST">
<br>
<select name="add" id="add">
<?php
$loadfile = "../add/add.php";
$fh = fopen($loadfile, 'r');
$theData = fread($fh, filesize($loadfile));
fclose($fh);
$load = explode(",", $theData);
for ($counter=0; $counter<count($load); $counter+=2) {
$cnt = $counter+1;
echo "<option name='members[]' value='$load[$counter]'>$load[$cnt]</option><br>";
}
?>
</select>
<p>
<center><input type='submit' class='grab' name ='submit' value='Save'></center>
</div>
</form>