php


php - How to ordering query result with answeroption float horizontal by a line


I want to order my query as I show below. :)
Table question
id question
100 What is your name?
101 What is your nick name?
Table answer
id answeroption questionid
1 John 100
2 Mike 100
3 Adam 100
4 Am 101
5 Den 101
So,i want the result show like this,with answeroption float horizontal by a line :
id question answer1 answer2 answer3
100 What is your name? John Mike Adam
101 What is your nick name? Am Den
The function query i used but i'm stuck to fix for result that i want actually.
function test($con){
$q = "select a.id, a.question, b.answeroption
from question a
inner join answer b
on a.id = b.questionid
";
$run = mysqli_query($con,$q);
$row = mysqli_fetch_array($run);
return $row;
}
You will want to use GROUP_CONCAT and GROUP BY
$q = "SELECT a.id, a.question, GROUP_CONCAT(b.answeroption) AS answeroptions
FROM question a
INNER JOIN answer b ON a.id = b.questionid
GROUP BY a.id
";

Related Links

Laravel Route get controller's construct without method
Highcharts doesn't show all contents of x-axis
Dynamic table with php pdo and two foreach
PHP color of the first line in a loop
Decrypt Rijndael with Passphrase in PHP
WP-API Get Posts After a Specific Date
How Do i Print last 10 days using php? [closed]
MySQL: Joining table duplicates SUM()
how to manuplate the google api php client
Unable to get cookie in construct function
How to loop through Models find from Where clause?
Trying to keep session with curl login in twitter
Code start and end in specific time
Return total values of each column after using datepicker to select a start and end date
file_put_contents on multiple request of XML data
How can i change this select sql statement into another select sql?

Categories

HOME
amazon-web-services
firebase
powerbi
protocol-buffers
matrix
yaml
xcode8.1
android-fragments
barcode-scanner
postgresql-9.4
slider
odata
bing-search
qooxdoo
share
clone
javafx-8
log4j2
lapack
spring-amqp
webstore
trace32
distributed-computing
corona
async-await
c#-7.0
infrared
clr
akka-persistence
stackexchange.redis
uislider
chronicle-queue
ipa
unrar
hdmi
onchange
tsung
rust-cargo
ms-media-foundation
redgate
testlink
django-crispy-forms
aurelia-http-client
spring-restcontroller
utf
secure-coding
access-denied
dbcc
morphline
qvtkwidget
section508
sony-future-lab-n
karabiner
extjs4.1
clrs
1010
dex
dynamics-crm-4
ipywidgets
clp
gcloud-node
uibinder
jeasyui
as3-api
vim-plugin
textpattern
bayesglm
fanotify
srv-record
google-gdk
ocmockito
python-curses
xhprof
visual-c++-2012
lumia-imaging-sdk
webautomation
senchatouch-2.4
bittorrent-sync
boolean-algebra
nosql-aggregation
django-sites
apache-shindig
application-server
mp4parser
stty
insertion
tfs-sdk
jquery-cycle
oembed
simplecov
coordinate
monocross
infopath-2007
representation
photo-management
regression-testing
ccnet-config
reliability
dm
downcasting
iphone-sdk-3.1.3
efs
service-factory

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App