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

Probluem in connecting to mongo database through PHP
how to pass multiple seession to a page in php
Create An Ajax Function To Update Records in Database using Yii Framework
Paypal email invoice
ddd - Where should synchronization with remote API go?
Two tables, display multiple results from one matching the ID
Undefined index php in inserting blob to database
how to implement SMPP connection to my website (cake php)
Codeigniter Multiple choice quiz app not submitting all the questions
Using PHP DOMDocument - extract all data between each h2
In php exec function can't put a variable's value in an INSERT statement [duplicate]
Is it possible to add action only at LOOP's final round?
doctrine2: deleting an entity with a ManytoMany relationship
Why does php-fpm ignore permissions defined for supplementary groups?
Join table fields with different ID in PHP
I am having 2 tables, 1st is friends and 2nd is post

Categories

HOME
visual-studio
apache-nifi
yaml
dotnetnuke
stacktrace.js
risk-management
tfs2015
jpa-criteria
bellman-ford
azure-graph-api
responsivevoice
xbap
twisted
phonegap-build
vertica
user-defined-types
l20n
hidden
office-ui-fabric
string-formatting
cloudsim
salt-cloud
spam
bazaar
jest
jitsi
bosun
gollum-wiki
software-packaging
dragula
environment
password-generator
clipboard
python-imageio
annotation-processing
unmarshalling
guice
windowsiot
memory-fences
epplus
universal
devtools
polyml
bluemixtools
android-alarms
xll
aurelia-http-client
gitolite
android-n
oauth2-playground
pyttsx
web-inspector
docker-ucp
tinyioc
openstack-glance
simple-schema
clrs
glassfish-4.1
rcharts
.when
zend-server
cognos-tm1
finder
ipywidgets
bigdecimal
ndk-build
dcount
jsf-2.3
between
maven-release-plugin
frame-grab
openmrs
android-expansion-files
variable-length-array
arbre
calcite
uitest
mobilefirst-server
textscan
com0com
ipod
ocmockito
subfolder
r.java-file
fiware-bosun
fasterxml
dc
device-admin
smacss
inequality
relationships
communicate
ivalueconverter
jomsocial
smips
reentrancy
ckeditor.net
jsplitpane
zend-pdf
voice-recording
uitextfielddelegate
dropshadow
type-safety
background-repeat
django-apps
boost-foreach
dip
libxslt
bucket
version-control-migration
word-automation

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App