PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm trying to create a dropdown list of dates which are retrieved from a DB. The problem I'm having is that it's creating multiple dates of the same date. I'm trying to generate an item in a drop down list, but if it already exists then not to add it to the list. Here is the the code so far:
If you build the list as an array first you can use one of two array methods (which one determined by how you build the array.
Method 1: build the array and then perform array_unique on it.
// While building complex unique array
if (isset($dates[$res['dlvdate']]) {
$element[$res['dlvdate']][]=$value;
} else {
$element[$res['dlvdate']]=array($value);
}
// later use array_keys to get the array of dates...
I can't imagine that working Volka as I still need it to select everything from the database but only display a single date once in a dropdown list.
Is there a function to re-arrange array index keys so they start at 0 and increment by 1. I ask this because using array_unique has caused a removal of some index keys so when I count the array and run a loop through the count it doesn't reach the end of the loop because the index keys are higher than the count.
impulse() wrote:I can't imagine that working Volka as I still need it to select everything from the database but only display a single date once in a dropdown list.
Your code snippet says different.
impulse() wrote:Is there a function to re-arrange array index keys so they start at 0 and increment by 1. I ask this because using array_unique has caused a removal of some index keys so when I count the array and run a loop through the count it doesn't reach the end of the loop because the index keys are higher than the count.