adding to arrays
I have a <select> with the <option> created by sorting through some arrays. this works fine but leaves gaps in the <select> which look a bit strange when they get big.
The <option> is a date, used in a booking process.
Is there a way of filling in these gaps with a single word like "Booked"?
I have read about array_push(), but this only seems to add to the end of an array and what I seem to need is something to fill in the gaps. Maybe something like:
or even an array that contains the word "Booked" as many times as needed (never more than 100).
I can't quite figure out how to get this to work or where to put the code.
Any suggestions gratefully recieved.
Here is how I am sorting the arrays (it might be ugly but it works):
$existing=array_merge($existing1, $existing2, $existing3, $existing4);/*creates the definitive existing array*/
$existing=array_unique($existing);/* removes duplicates */
$select_date=array_diff($option2_date,$existing);/* subtracts the existing dates from the selected dates */
$select_date=array_unique($select_date);/* removes any posible duplicates */
echo"<option value=\"$select_date[$i]\">$select_date[$i]<br /></option>";
Why are you doing this:
I would do something more like:
That will only loop through all the values of $select_date.
Ok, I was using the:
because I am generating 100 <option>s in the <select>, but your solution:
is prettier. Thank you, Pyro.
Trouble is, I have still got the gaps in the <select>.
The <option>s are a list of dates (the difference between one that are in the DB, ie booked, and the ones that are not) and for the sake of readability and useability I want to keep the gaps.
The gaps are currently blank, which is acceptable but not perfect.
I don't want to remove the gaps because I think that users would expect to find a four "week" gap between January and March (if all of the weeks (4) in February are booked.
Really I just want to fill in those gaps with the word "Booked" and wondered if you could do it by creating another array(), maybe:
$booked=array('Booked', + 'Booked', another 99 times);
and slotting it in the gaps in $selected_date.
or maybe using array_splice() or in_array() somehow.
Any input gratefully recieved.
Last edited by awebb; 07-08-2003 at 02:45 AM.
I'm assuming that this didn't work?
Note that it would have to go inside your for loop...
Er...yes, actually it does work.
I had it in the wrong place ie before the for loop, trying to fill the flipping holes before it outputted.
Many thanks for your help.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)