Question : Slash between values question

Hello experts!

I have 10 columns in my database called table_nightclub_1, table_nightclub_2, table_nightclub_3, table_nightclub_4 and so on. Datatype = enum('Y', 'N', '').

Y if the table is booked - N if not.

How can I echo '1 / 2 / 3' if table 1, 2 and 3 are booked? And only '1' if table 1 is booked? '8 / 9' if table 8 and 9 are booked.

I can't find a smart way to make a slash between the values:-/ Hope someone can help me!

Thanks in advance!

Answer : Slash between values question

You're not on V5.3?

Old style equivalent.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
<?php
// Assuming data coming from database is in 1 row.
$data = array
	(
	'table_nightclub_1' => 'Y',
	'table_nightclub_2' => 'N',
	'table_nightclub_3' => 'N',
	'table_nightclub_4' => 'Y',
	'table_nightclub_5' => 'N',
	'table_nightclub_6' => 'N',
	'table_nightclub_7' => 'Y',
	'table_nightclub_8' => 'N',
	'table_nightclub_9' => 'N',
	'table_nightclub_10' => 'Y',
	);

function Step1($value)
	{
	return 'N' != $value;
	}

function Step3($value)
	{
	return substr($value, strlen('table_nightclub_'));
	}

echo
	implode // Step 4 : Implode them.
		(
		' / ',
		array_map // Step 3 : Drop the textual part of the keys.
			(
			'Step3',
			array_keys // Step 2 : Get the keys from the remaining 'Y's.
				(
				array_filter // Step 1 : Remove 'N's from array.
					(
					$data,
					'Step1'
					)
				)
			)
		);
Random Solutions  
 
programming4us programming4us