Skip to content
Advertisement

Combining multiple queries into an output

With a feedback survey they can select bad, neutral or good. I want to compile the bad and good into a table. I am trying to create a tally “table” output from an ajax request to replace a div content. Ideally it will look like:

Experience Negative Positive
Cleanliness 12 18
Check-In/Out 4 30
Food 2 12
Staff 1 8

So my mysql has columns for cleanliness, food, etc. Inside is ratings of negative/neutral/positive.

I thought of using a single php script to populate the table, and came up with this so far:

I make two queries:

JavaScript

Then fetch them:

JavaScript

Now, they are arrayed but how to assemble both in an output? I can’t Key => Value => Value right?

JavaScript

So I get my negative and positive but now no row “title”. If I just output the array, I can get the row title but only one of the counts.

Should I scrap trying to combine in a single script and create a “generic” script and POST the column and desired response for just a single count output? That will be a lot of ajax queries hitting the same php script.

Thanks!

SQL fiddle, not sure how to make the right side do what my php is doing with PDO. http://sqlfiddle.com/#!9/37c0c2e/7

Advertisement

Answer

You could obtain the table using a single UNION query

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement