MySQL SELECT * with same ID from a table based on row click (js) of a previous table with that ID












2














I have three tables: learners, sessions and enrollments. Please see relationships image bellow:



Relationships Image



Now to explain how I've set this up: I'm using DataTables for sessions, on record click of a session I get a popup with all its record details - I have used something like the below. Plus a further note on this, I'm not using Ajax, only html, php, mysql and js to interact with the database:



Script:



$('#table_id tbody').on('click', 'tr', function () {    
var data = dataTable.row( this ).data();
modal.style.display = "block";
$('#Course').html(data[1]);
$('#Begin').html(data[2]);
$('#End').html(data[3]);
$('#Location').html(data[4]);
$('#Trainer').html(data[5]);
$('#Type').html(data[6]);
});


HTML



<!--Fetch session prints here-->
<p id="Course"><span id="Course"></p>
<p id="sess_desc">
<b>Offered: </b><span id="Begin"></span> to <span id="End"></span><br />
<b>Location: </b><span id="Location"></span><br />
<b>Trainer: </b><span id="Trainer"></span><br />
<b>Training Type: </b><span id="Type"></span>
</p>


See here: Popup Image



I'd like to know how to display enrolled learners from the clicked session table. I'm unable to create an SQL query based on the js "click" event of this row, which would allow me to display all enrolments based on clicked rows ID.



I've tried this but it doesn't work for me as I'm unable to structure my query based on the clicked session record:



                            <div id="modal_showlearners">
<p>Learners enrolled in this session:</p>
<form action="#" method="post">
<?php
$result = mysqli_query($con, "SELECT * FROM enrolments WHERE SessionID = sessions." . $row['ID'] . "") or die (mysqli_error());
while ( $row=mysqli_fetch_assoc($result)) {
echo $row['SessionID'] . " " . $row['LearnerID'] . " " . $row['FirstName'] . "<br />";
}

?>
</form>
</div>


Hope I've given enough information, I've been struggling with this for over 2 weeks now. Any help would be appreciated, thanks.










share|improve this question




















  • 1




    if you want to do something to your database based on client side interaction, you need to either submit a form or send an ajax request. one way or another, the server needs to know what happened and update/insert rows accordingly
    – billynoah
    Nov 22 '18 at 0:08






  • 1




    also, this is way too much information - we don't really need to know I was able to do this and I was able to do that – this is mostly just seen as noise and decreases the likelihood of someone reading your question all the way through. Try to edit this question to be a bit more concise about where you hit a wall and what you want to do. You will get more responses this way.
    – billynoah
    Nov 22 '18 at 0:10










  • I've edited my post. Upon doing this I figured that JS is processed only after PHP, so running lots of PHP scripts on a single page are all processed at once, even the one within the modal popup which I was assuming will be run after the popup pops.
    – Moses
    Nov 22 '18 at 1:24










  • as I said, to interact with your database based on clicks, you need ajax. the basic idea is, (1) set up an event that triggers an ajax request on a click event, (2) receive the request on your server, run a query and return either html to display or a json to parse, (3) render the data on your page in the success() callback
    – billynoah
    Nov 22 '18 at 1:59
















2














I have three tables: learners, sessions and enrollments. Please see relationships image bellow:



Relationships Image



Now to explain how I've set this up: I'm using DataTables for sessions, on record click of a session I get a popup with all its record details - I have used something like the below. Plus a further note on this, I'm not using Ajax, only html, php, mysql and js to interact with the database:



Script:



$('#table_id tbody').on('click', 'tr', function () {    
var data = dataTable.row( this ).data();
modal.style.display = "block";
$('#Course').html(data[1]);
$('#Begin').html(data[2]);
$('#End').html(data[3]);
$('#Location').html(data[4]);
$('#Trainer').html(data[5]);
$('#Type').html(data[6]);
});


HTML



<!--Fetch session prints here-->
<p id="Course"><span id="Course"></p>
<p id="sess_desc">
<b>Offered: </b><span id="Begin"></span> to <span id="End"></span><br />
<b>Location: </b><span id="Location"></span><br />
<b>Trainer: </b><span id="Trainer"></span><br />
<b>Training Type: </b><span id="Type"></span>
</p>


See here: Popup Image



I'd like to know how to display enrolled learners from the clicked session table. I'm unable to create an SQL query based on the js "click" event of this row, which would allow me to display all enrolments based on clicked rows ID.



I've tried this but it doesn't work for me as I'm unable to structure my query based on the clicked session record:



                            <div id="modal_showlearners">
<p>Learners enrolled in this session:</p>
<form action="#" method="post">
<?php
$result = mysqli_query($con, "SELECT * FROM enrolments WHERE SessionID = sessions." . $row['ID'] . "") or die (mysqli_error());
while ( $row=mysqli_fetch_assoc($result)) {
echo $row['SessionID'] . " " . $row['LearnerID'] . " " . $row['FirstName'] . "<br />";
}

?>
</form>
</div>


Hope I've given enough information, I've been struggling with this for over 2 weeks now. Any help would be appreciated, thanks.










share|improve this question




















  • 1




    if you want to do something to your database based on client side interaction, you need to either submit a form or send an ajax request. one way or another, the server needs to know what happened and update/insert rows accordingly
    – billynoah
    Nov 22 '18 at 0:08






  • 1




    also, this is way too much information - we don't really need to know I was able to do this and I was able to do that – this is mostly just seen as noise and decreases the likelihood of someone reading your question all the way through. Try to edit this question to be a bit more concise about where you hit a wall and what you want to do. You will get more responses this way.
    – billynoah
    Nov 22 '18 at 0:10










  • I've edited my post. Upon doing this I figured that JS is processed only after PHP, so running lots of PHP scripts on a single page are all processed at once, even the one within the modal popup which I was assuming will be run after the popup pops.
    – Moses
    Nov 22 '18 at 1:24










  • as I said, to interact with your database based on clicks, you need ajax. the basic idea is, (1) set up an event that triggers an ajax request on a click event, (2) receive the request on your server, run a query and return either html to display or a json to parse, (3) render the data on your page in the success() callback
    – billynoah
    Nov 22 '18 at 1:59














2












2








2







I have three tables: learners, sessions and enrollments. Please see relationships image bellow:



Relationships Image



Now to explain how I've set this up: I'm using DataTables for sessions, on record click of a session I get a popup with all its record details - I have used something like the below. Plus a further note on this, I'm not using Ajax, only html, php, mysql and js to interact with the database:



Script:



$('#table_id tbody').on('click', 'tr', function () {    
var data = dataTable.row( this ).data();
modal.style.display = "block";
$('#Course').html(data[1]);
$('#Begin').html(data[2]);
$('#End').html(data[3]);
$('#Location').html(data[4]);
$('#Trainer').html(data[5]);
$('#Type').html(data[6]);
});


HTML



<!--Fetch session prints here-->
<p id="Course"><span id="Course"></p>
<p id="sess_desc">
<b>Offered: </b><span id="Begin"></span> to <span id="End"></span><br />
<b>Location: </b><span id="Location"></span><br />
<b>Trainer: </b><span id="Trainer"></span><br />
<b>Training Type: </b><span id="Type"></span>
</p>


See here: Popup Image



I'd like to know how to display enrolled learners from the clicked session table. I'm unable to create an SQL query based on the js "click" event of this row, which would allow me to display all enrolments based on clicked rows ID.



I've tried this but it doesn't work for me as I'm unable to structure my query based on the clicked session record:



                            <div id="modal_showlearners">
<p>Learners enrolled in this session:</p>
<form action="#" method="post">
<?php
$result = mysqli_query($con, "SELECT * FROM enrolments WHERE SessionID = sessions." . $row['ID'] . "") or die (mysqli_error());
while ( $row=mysqli_fetch_assoc($result)) {
echo $row['SessionID'] . " " . $row['LearnerID'] . " " . $row['FirstName'] . "<br />";
}

?>
</form>
</div>


Hope I've given enough information, I've been struggling with this for over 2 weeks now. Any help would be appreciated, thanks.










share|improve this question















I have three tables: learners, sessions and enrollments. Please see relationships image bellow:



Relationships Image



Now to explain how I've set this up: I'm using DataTables for sessions, on record click of a session I get a popup with all its record details - I have used something like the below. Plus a further note on this, I'm not using Ajax, only html, php, mysql and js to interact with the database:



Script:



$('#table_id tbody').on('click', 'tr', function () {    
var data = dataTable.row( this ).data();
modal.style.display = "block";
$('#Course').html(data[1]);
$('#Begin').html(data[2]);
$('#End').html(data[3]);
$('#Location').html(data[4]);
$('#Trainer').html(data[5]);
$('#Type').html(data[6]);
});


HTML



<!--Fetch session prints here-->
<p id="Course"><span id="Course"></p>
<p id="sess_desc">
<b>Offered: </b><span id="Begin"></span> to <span id="End"></span><br />
<b>Location: </b><span id="Location"></span><br />
<b>Trainer: </b><span id="Trainer"></span><br />
<b>Training Type: </b><span id="Type"></span>
</p>


See here: Popup Image



I'd like to know how to display enrolled learners from the clicked session table. I'm unable to create an SQL query based on the js "click" event of this row, which would allow me to display all enrolments based on clicked rows ID.



I've tried this but it doesn't work for me as I'm unable to structure my query based on the clicked session record:



                            <div id="modal_showlearners">
<p>Learners enrolled in this session:</p>
<form action="#" method="post">
<?php
$result = mysqli_query($con, "SELECT * FROM enrolments WHERE SessionID = sessions." . $row['ID'] . "") or die (mysqli_error());
while ( $row=mysqli_fetch_assoc($result)) {
echo $row['SessionID'] . " " . $row['LearnerID'] . " " . $row['FirstName'] . "<br />";
}

?>
</form>
</div>


Hope I've given enough information, I've been struggling with this for over 2 weeks now. Any help would be appreciated, thanks.







javascript php jquery html mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 0:40









SherylHohman

4,64263246




4,64263246










asked Nov 21 '18 at 22:37









MosesMoses

117




117








  • 1




    if you want to do something to your database based on client side interaction, you need to either submit a form or send an ajax request. one way or another, the server needs to know what happened and update/insert rows accordingly
    – billynoah
    Nov 22 '18 at 0:08






  • 1




    also, this is way too much information - we don't really need to know I was able to do this and I was able to do that – this is mostly just seen as noise and decreases the likelihood of someone reading your question all the way through. Try to edit this question to be a bit more concise about where you hit a wall and what you want to do. You will get more responses this way.
    – billynoah
    Nov 22 '18 at 0:10










  • I've edited my post. Upon doing this I figured that JS is processed only after PHP, so running lots of PHP scripts on a single page are all processed at once, even the one within the modal popup which I was assuming will be run after the popup pops.
    – Moses
    Nov 22 '18 at 1:24










  • as I said, to interact with your database based on clicks, you need ajax. the basic idea is, (1) set up an event that triggers an ajax request on a click event, (2) receive the request on your server, run a query and return either html to display or a json to parse, (3) render the data on your page in the success() callback
    – billynoah
    Nov 22 '18 at 1:59














  • 1




    if you want to do something to your database based on client side interaction, you need to either submit a form or send an ajax request. one way or another, the server needs to know what happened and update/insert rows accordingly
    – billynoah
    Nov 22 '18 at 0:08






  • 1




    also, this is way too much information - we don't really need to know I was able to do this and I was able to do that – this is mostly just seen as noise and decreases the likelihood of someone reading your question all the way through. Try to edit this question to be a bit more concise about where you hit a wall and what you want to do. You will get more responses this way.
    – billynoah
    Nov 22 '18 at 0:10










  • I've edited my post. Upon doing this I figured that JS is processed only after PHP, so running lots of PHP scripts on a single page are all processed at once, even the one within the modal popup which I was assuming will be run after the popup pops.
    – Moses
    Nov 22 '18 at 1:24










  • as I said, to interact with your database based on clicks, you need ajax. the basic idea is, (1) set up an event that triggers an ajax request on a click event, (2) receive the request on your server, run a query and return either html to display or a json to parse, (3) render the data on your page in the success() callback
    – billynoah
    Nov 22 '18 at 1:59








1




1




if you want to do something to your database based on client side interaction, you need to either submit a form or send an ajax request. one way or another, the server needs to know what happened and update/insert rows accordingly
– billynoah
Nov 22 '18 at 0:08




if you want to do something to your database based on client side interaction, you need to either submit a form or send an ajax request. one way or another, the server needs to know what happened and update/insert rows accordingly
– billynoah
Nov 22 '18 at 0:08




1




1




also, this is way too much information - we don't really need to know I was able to do this and I was able to do that – this is mostly just seen as noise and decreases the likelihood of someone reading your question all the way through. Try to edit this question to be a bit more concise about where you hit a wall and what you want to do. You will get more responses this way.
– billynoah
Nov 22 '18 at 0:10




also, this is way too much information - we don't really need to know I was able to do this and I was able to do that – this is mostly just seen as noise and decreases the likelihood of someone reading your question all the way through. Try to edit this question to be a bit more concise about where you hit a wall and what you want to do. You will get more responses this way.
– billynoah
Nov 22 '18 at 0:10












I've edited my post. Upon doing this I figured that JS is processed only after PHP, so running lots of PHP scripts on a single page are all processed at once, even the one within the modal popup which I was assuming will be run after the popup pops.
– Moses
Nov 22 '18 at 1:24




I've edited my post. Upon doing this I figured that JS is processed only after PHP, so running lots of PHP scripts on a single page are all processed at once, even the one within the modal popup which I was assuming will be run after the popup pops.
– Moses
Nov 22 '18 at 1:24












as I said, to interact with your database based on clicks, you need ajax. the basic idea is, (1) set up an event that triggers an ajax request on a click event, (2) receive the request on your server, run a query and return either html to display or a json to parse, (3) render the data on your page in the success() callback
– billynoah
Nov 22 '18 at 1:59




as I said, to interact with your database based on clicks, you need ajax. the basic idea is, (1) set up an event that triggers an ajax request on a click event, (2) receive the request on your server, run a query and return either html to display or a json to parse, (3) render the data on your page in the success() callback
– billynoah
Nov 22 '18 at 1:59












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421405%2fmysql-select-with-same-id-from-a-table-based-on-row-click-js-of-a-previous-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421405%2fmysql-select-with-same-id-from-a-table-based-on-row-click-js-of-a-previous-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'