I need help with storing values from a sql query into variables. The problem is in order to get the appropriate values I jad to write a long UNION query. There are only two columns, and not many results. Ideally, I want to create a variable for each row where the variable name is the result from the first column and the corresponding value for that variable would be the result from the second column.
Here is the UNION query:
SELECT 'mon_m' as shift, count(mon_m) as count
FROM schedule
WHERE week_of = '2013-12-23'
AND mon_m <> ''
UNION
SELECT 'mon_a', COUNT(mon_a)
FROM schedule
WHERE week_of = '2013-12-23'
AND mon_a <> ''
UNION
SELECT 'mon_n', COUNT(mon_n)
FROM schedule
WHERE week_of = '2013-12-23'
AND mon_n <> ''
UNION
SELECT 'tue_m', count(tue_m)
FROM schedule
WHERE week_of = '2013-12-23'
AND tue_m <> ''
UNION
SELECT 'tue_a', COUNT(tue_a)
FROM schedule
WHERE week_of = '2013-12-23'
AND tue_a <> ''
UNION
SELECT 'tue_n', COUNT(tue_n)
FROM schedule
WHERE week_of = '2013-12-23'
AND tue_n <> ''
UNION
SELECT 'wed_m', count(wed_m)
FROM schedule
WHERE week_of = '2013-12-23'
AND wed_m <> ''
UNION
SELECT 'wed_a', COUNT(wed_a)
FROM schedule
WHERE week_of = '2013-12-23'
AND wed_a <> ''
UNION
SELECT 'wed_n', COUNT(wed_n)
FROM schedule
WHERE week_of = '2013-12-23'
AND wed_n <> ''
UNION
SELECT 'thu_m', count(thu_m)
FROM schedule
WHERE week_of = '2013-12-23'
AND thu_m <> ''
UNION
SELECT 'thu_a', COUNT(thu_a)
FROM schedule
WHERE week_of = '2013-12-23'
AND thu_a <> ''
UNION
SELECT 'thu_n', COUNT(thu_n)
FROM schedule
WHERE week_of = '2013-12-23'
AND thu_n <> ''
UNION
SELECT 'fri_m', count(fri_m)
FROM schedule
WHERE week_of = '2013-12-23'
AND fri_m <> ''
UNION
SELECT 'fri_a', COUNT(fri_a)
FROM schedule
WHERE week_of = '2013-12-23'
AND fri_a <> ''
UNION
SELECT 'fri_n', COUNT(fri_n)
FROM schedule
WHERE week_of = '2013-12-23'
AND fri_n <> ''
UNION
SELECT 'sat', count(sat)
FROM schedule
WHERE week_of = '2013-12-23'
AND sat <> ''
UNION
SELECT 'sun', COUNT(sun)
FROM schedule
WHERE week_of = '2013-12-23'
AND sun <> ''
Here is a small sample of what the data would like:
ColumnA ColumnB
mon_m 1
mon_a 5
mon_n 6
tue_m 3
tue_a 6
tue_n 2
I need to access these values using php so I can build a table. I'd like to access them using variables. For example:
echo $mon_m
echo $mon_a
echo $mon_n
Where
$mon_m = 1
$mon_a = 5
$mon_n = 6
I have the SQL statement ready to go and need some help with getting these values into php variables.