php refreshing only data in page
i'm a php nearby. I have a problem with my form. I connect the controller with db and extract a question and his three answers. If i click on one of this, the system return the second question, under the first question. If i click on one of the seconds answers, the system return the thirth question overwrite the second question.
I would like that second question (and its answers) overwrite the first (and its answers). How i can?
db structure
view
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
$controllers->cercaDomanda(1);
$controllers->cercaRisposta(1);
$controllers->cercaNuovoId($id);
?>
2) Controller.php
<?php
require_once('models/Domanda.php');
require_once('models/Risposta.php');
require_once ('models/Model.php');
class Controller {
public $domanda;
public $risposta;
public $model;
public function __construct(){
$this->domande = new Domanda(); //istanziamo la classe domanda
$this->risposte = new Risposta(); //istanziamo la classe risposta
$this->model = new Model(); //istanziamo la classe risposta
}
public function cercaDomanda($id){
$reslt = $this->domande->getDomanda($id);
include 'views/basicView.php';
}
public function cercaRisposta($id){
$reslt2 = $this->risposte->getRisposta($id);
include 'views/basicView.php';
}
public function cercaNuovoId($id){
include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
$reslt4 = $this->cercaDomanda($reslt3);
$reslt5 = $this->cercaRisposta($reslt3);
}
}
?>
3)Domanda.php
<?php
require_once 'models/Domanda.php';
class Domanda {
public function getDomanda($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT domanda FROM public."Domande" WHERE "id"='.$id;
$result = pg_query($query);
return $result;
pg_close($dbconnection);
}
}
?>
4)Risposta.php
<?php
require_once 'models/Risposta.php';
class Risposta {
public function getRisposta($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT * FROM public."Risposte" WHERE "id_domanda"='.$id;
$result = pg_query($query); //or die ('Query fallita: ' .pg_last_error());
return $result;
pg_close($dbconnection);
}
}
?>
5)Model.php
<?php
require_once 'models/Model.php';
class Model {
public function getIdNext(){
if(isset($_POST['btnScelta'])){
$result = $_POST['btnScelta'];
return $result;
}
}
}
6)View
<html>
<head></head>
<body>
<form action='index.php' name='chatbotyForm' method="POST">
<table>
<?php
echo "<tr>";
$domanda = pg_fetch_array($reslt, null, PGSQL_ASSOC);
print $domanda['domanda'];
echo "</tr>";
?>
</table>
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
</form>
</body>
</html>
php page-refresh
add a comment |
i'm a php nearby. I have a problem with my form. I connect the controller with db and extract a question and his three answers. If i click on one of this, the system return the second question, under the first question. If i click on one of the seconds answers, the system return the thirth question overwrite the second question.
I would like that second question (and its answers) overwrite the first (and its answers). How i can?
db structure
view
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
$controllers->cercaDomanda(1);
$controllers->cercaRisposta(1);
$controllers->cercaNuovoId($id);
?>
2) Controller.php
<?php
require_once('models/Domanda.php');
require_once('models/Risposta.php');
require_once ('models/Model.php');
class Controller {
public $domanda;
public $risposta;
public $model;
public function __construct(){
$this->domande = new Domanda(); //istanziamo la classe domanda
$this->risposte = new Risposta(); //istanziamo la classe risposta
$this->model = new Model(); //istanziamo la classe risposta
}
public function cercaDomanda($id){
$reslt = $this->domande->getDomanda($id);
include 'views/basicView.php';
}
public function cercaRisposta($id){
$reslt2 = $this->risposte->getRisposta($id);
include 'views/basicView.php';
}
public function cercaNuovoId($id){
include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
$reslt4 = $this->cercaDomanda($reslt3);
$reslt5 = $this->cercaRisposta($reslt3);
}
}
?>
3)Domanda.php
<?php
require_once 'models/Domanda.php';
class Domanda {
public function getDomanda($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT domanda FROM public."Domande" WHERE "id"='.$id;
$result = pg_query($query);
return $result;
pg_close($dbconnection);
}
}
?>
4)Risposta.php
<?php
require_once 'models/Risposta.php';
class Risposta {
public function getRisposta($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT * FROM public."Risposte" WHERE "id_domanda"='.$id;
$result = pg_query($query); //or die ('Query fallita: ' .pg_last_error());
return $result;
pg_close($dbconnection);
}
}
?>
5)Model.php
<?php
require_once 'models/Model.php';
class Model {
public function getIdNext(){
if(isset($_POST['btnScelta'])){
$result = $_POST['btnScelta'];
return $result;
}
}
}
6)View
<html>
<head></head>
<body>
<form action='index.php' name='chatbotyForm' method="POST">
<table>
<?php
echo "<tr>";
$domanda = pg_fetch_array($reslt, null, PGSQL_ASSOC);
print $domanda['domanda'];
echo "</tr>";
?>
</table>
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
</form>
</body>
</html>
php page-refresh
You want to look at MySQL'sORDER BY
clause
– Martin
Nov 20 '18 at 16:11
Possible duplicate of How can I reorder rows in sql database
– Martin
Nov 20 '18 at 16:11
No, i have postgresql and my problem isn't in db but in view. I call the questions and relative answers with id, there is no order.
– Kurtbain
Nov 21 '18 at 9:41
SQL is (partially) standard,ORDER BY
is the same in MySQL and in PostgreSQL. "There is no order" - implement one!
– DanFromGermany
Nov 21 '18 at 11:29
yes, but i don't have db problems. i have a problem of viewing. I would like the first question and it's relative answers disappear as the other.
– Kurtbain
Nov 21 '18 at 14:53
add a comment |
i'm a php nearby. I have a problem with my form. I connect the controller with db and extract a question and his three answers. If i click on one of this, the system return the second question, under the first question. If i click on one of the seconds answers, the system return the thirth question overwrite the second question.
I would like that second question (and its answers) overwrite the first (and its answers). How i can?
db structure
view
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
$controllers->cercaDomanda(1);
$controllers->cercaRisposta(1);
$controllers->cercaNuovoId($id);
?>
2) Controller.php
<?php
require_once('models/Domanda.php');
require_once('models/Risposta.php');
require_once ('models/Model.php');
class Controller {
public $domanda;
public $risposta;
public $model;
public function __construct(){
$this->domande = new Domanda(); //istanziamo la classe domanda
$this->risposte = new Risposta(); //istanziamo la classe risposta
$this->model = new Model(); //istanziamo la classe risposta
}
public function cercaDomanda($id){
$reslt = $this->domande->getDomanda($id);
include 'views/basicView.php';
}
public function cercaRisposta($id){
$reslt2 = $this->risposte->getRisposta($id);
include 'views/basicView.php';
}
public function cercaNuovoId($id){
include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
$reslt4 = $this->cercaDomanda($reslt3);
$reslt5 = $this->cercaRisposta($reslt3);
}
}
?>
3)Domanda.php
<?php
require_once 'models/Domanda.php';
class Domanda {
public function getDomanda($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT domanda FROM public."Domande" WHERE "id"='.$id;
$result = pg_query($query);
return $result;
pg_close($dbconnection);
}
}
?>
4)Risposta.php
<?php
require_once 'models/Risposta.php';
class Risposta {
public function getRisposta($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT * FROM public."Risposte" WHERE "id_domanda"='.$id;
$result = pg_query($query); //or die ('Query fallita: ' .pg_last_error());
return $result;
pg_close($dbconnection);
}
}
?>
5)Model.php
<?php
require_once 'models/Model.php';
class Model {
public function getIdNext(){
if(isset($_POST['btnScelta'])){
$result = $_POST['btnScelta'];
return $result;
}
}
}
6)View
<html>
<head></head>
<body>
<form action='index.php' name='chatbotyForm' method="POST">
<table>
<?php
echo "<tr>";
$domanda = pg_fetch_array($reslt, null, PGSQL_ASSOC);
print $domanda['domanda'];
echo "</tr>";
?>
</table>
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
</form>
</body>
</html>
php page-refresh
i'm a php nearby. I have a problem with my form. I connect the controller with db and extract a question and his three answers. If i click on one of this, the system return the second question, under the first question. If i click on one of the seconds answers, the system return the thirth question overwrite the second question.
I would like that second question (and its answers) overwrite the first (and its answers). How i can?
db structure
view
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
$controllers->cercaDomanda(1);
$controllers->cercaRisposta(1);
$controllers->cercaNuovoId($id);
?>
2) Controller.php
<?php
require_once('models/Domanda.php');
require_once('models/Risposta.php');
require_once ('models/Model.php');
class Controller {
public $domanda;
public $risposta;
public $model;
public function __construct(){
$this->domande = new Domanda(); //istanziamo la classe domanda
$this->risposte = new Risposta(); //istanziamo la classe risposta
$this->model = new Model(); //istanziamo la classe risposta
}
public function cercaDomanda($id){
$reslt = $this->domande->getDomanda($id);
include 'views/basicView.php';
}
public function cercaRisposta($id){
$reslt2 = $this->risposte->getRisposta($id);
include 'views/basicView.php';
}
public function cercaNuovoId($id){
include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
$reslt4 = $this->cercaDomanda($reslt3);
$reslt5 = $this->cercaRisposta($reslt3);
}
}
?>
3)Domanda.php
<?php
require_once 'models/Domanda.php';
class Domanda {
public function getDomanda($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT domanda FROM public."Domande" WHERE "id"='.$id;
$result = pg_query($query);
return $result;
pg_close($dbconnection);
}
}
?>
4)Risposta.php
<?php
require_once 'models/Risposta.php';
class Risposta {
public function getRisposta($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT * FROM public."Risposte" WHERE "id_domanda"='.$id;
$result = pg_query($query); //or die ('Query fallita: ' .pg_last_error());
return $result;
pg_close($dbconnection);
}
}
?>
5)Model.php
<?php
require_once 'models/Model.php';
class Model {
public function getIdNext(){
if(isset($_POST['btnScelta'])){
$result = $_POST['btnScelta'];
return $result;
}
}
}
6)View
<html>
<head></head>
<body>
<form action='index.php' name='chatbotyForm' method="POST">
<table>
<?php
echo "<tr>";
$domanda = pg_fetch_array($reslt, null, PGSQL_ASSOC);
print $domanda['domanda'];
echo "</tr>";
?>
</table>
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
</form>
</body>
</html>
php page-refresh
php page-refresh
edited Nov 22 '18 at 9:10
Kurtbain
asked Nov 20 '18 at 16:08
KurtbainKurtbain
33
33
You want to look at MySQL'sORDER BY
clause
– Martin
Nov 20 '18 at 16:11
Possible duplicate of How can I reorder rows in sql database
– Martin
Nov 20 '18 at 16:11
No, i have postgresql and my problem isn't in db but in view. I call the questions and relative answers with id, there is no order.
– Kurtbain
Nov 21 '18 at 9:41
SQL is (partially) standard,ORDER BY
is the same in MySQL and in PostgreSQL. "There is no order" - implement one!
– DanFromGermany
Nov 21 '18 at 11:29
yes, but i don't have db problems. i have a problem of viewing. I would like the first question and it's relative answers disappear as the other.
– Kurtbain
Nov 21 '18 at 14:53
add a comment |
You want to look at MySQL'sORDER BY
clause
– Martin
Nov 20 '18 at 16:11
Possible duplicate of How can I reorder rows in sql database
– Martin
Nov 20 '18 at 16:11
No, i have postgresql and my problem isn't in db but in view. I call the questions and relative answers with id, there is no order.
– Kurtbain
Nov 21 '18 at 9:41
SQL is (partially) standard,ORDER BY
is the same in MySQL and in PostgreSQL. "There is no order" - implement one!
– DanFromGermany
Nov 21 '18 at 11:29
yes, but i don't have db problems. i have a problem of viewing. I would like the first question and it's relative answers disappear as the other.
– Kurtbain
Nov 21 '18 at 14:53
You want to look at MySQL's
ORDER BY
clause– Martin
Nov 20 '18 at 16:11
You want to look at MySQL's
ORDER BY
clause– Martin
Nov 20 '18 at 16:11
Possible duplicate of How can I reorder rows in sql database
– Martin
Nov 20 '18 at 16:11
Possible duplicate of How can I reorder rows in sql database
– Martin
Nov 20 '18 at 16:11
No, i have postgresql and my problem isn't in db but in view. I call the questions and relative answers with id, there is no order.
– Kurtbain
Nov 21 '18 at 9:41
No, i have postgresql and my problem isn't in db but in view. I call the questions and relative answers with id, there is no order.
– Kurtbain
Nov 21 '18 at 9:41
SQL is (partially) standard,
ORDER BY
is the same in MySQL and in PostgreSQL. "There is no order" - implement one!– DanFromGermany
Nov 21 '18 at 11:29
SQL is (partially) standard,
ORDER BY
is the same in MySQL and in PostgreSQL. "There is no order" - implement one!– DanFromGermany
Nov 21 '18 at 11:29
yes, but i don't have db problems. i have a problem of viewing. I would like the first question and it's relative answers disappear as the other.
– Kurtbain
Nov 21 '18 at 14:53
yes, but i don't have db problems. i have a problem of viewing. I would like the first question and it's relative answers disappear as the other.
– Kurtbain
Nov 21 '18 at 14:53
add a comment |
1 Answer
1
active
oldest
votes
In your view:
...
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
you are setting only one value in each button. which is available as $_POST['btnScelta']
and that is used to render your last question.
Edit previous contents removed because they are not relevant to the question.
To render two questions pass two ids as the button value.
To remove the first question remove the two lines from your index.php
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
/* remove the following two lines the first question wont be rendered.*/
//$controllers->cercaDomanda(1);
//$controllers->cercaRisposta(1);
$controllers->cercaNuovoId(/*$id*/);
?>
Now make controller process two question display.
class Controller {
public function cercaNuovoId(/*$id*/){
// include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
// render previous question only if a value exists.
if ($result3) {
list($current, $previous) = explode(',', $result3);
$this->cercaDomanda($previous);
$this->cercaRisposta($previous);
}
// show the first question on first visit.
if (empty($current)){
$current = 1;
}
$reslt4 = $this->cercaDomanda($current);
$reslt5 = $this->cercaRisposta($current);
}
}
Now in the view make modification for button to have two values seperated by comma. current question id is available as $id from Controller::cercaRisposta()
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='{$rispost->id_domanda_successiva},{id}'>$rispost->risposta</button>
</td>";
}
?>
</form>
you can also pass the previous question id by changing form's action property with a query like index.php?previous=$id
.
Thanks for all! But this non change my problem. The first question and it's relative questions do not disappear. I leave the db structure in post.
– Kurtbain
Nov 21 '18 at 14:52
reading through the comments in question, I realize my understanding of your question was not correct. Let me know when you clickliceo scientifico
whether you want to show the third questionDi dove sei?
and its answers(relative questions?) only OR both second and third question with its answers and not show first question.
– Boban
Nov 21 '18 at 16:29
updated the answer, please see.
– Boban
Nov 21 '18 at 17:29
I would like that second question (and its answers) overwrite the first (and its answers). Sorry for delay
– Kurtbain
Nov 22 '18 at 9:09
Alright, The answer is updated for that. Please verify.
– Boban
Nov 22 '18 at 9:35
|
show 2 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397027%2fphp-refreshing-only-data-in-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your view:
...
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
you are setting only one value in each button. which is available as $_POST['btnScelta']
and that is used to render your last question.
Edit previous contents removed because they are not relevant to the question.
To render two questions pass two ids as the button value.
To remove the first question remove the two lines from your index.php
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
/* remove the following two lines the first question wont be rendered.*/
//$controllers->cercaDomanda(1);
//$controllers->cercaRisposta(1);
$controllers->cercaNuovoId(/*$id*/);
?>
Now make controller process two question display.
class Controller {
public function cercaNuovoId(/*$id*/){
// include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
// render previous question only if a value exists.
if ($result3) {
list($current, $previous) = explode(',', $result3);
$this->cercaDomanda($previous);
$this->cercaRisposta($previous);
}
// show the first question on first visit.
if (empty($current)){
$current = 1;
}
$reslt4 = $this->cercaDomanda($current);
$reslt5 = $this->cercaRisposta($current);
}
}
Now in the view make modification for button to have two values seperated by comma. current question id is available as $id from Controller::cercaRisposta()
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='{$rispost->id_domanda_successiva},{id}'>$rispost->risposta</button>
</td>";
}
?>
</form>
you can also pass the previous question id by changing form's action property with a query like index.php?previous=$id
.
Thanks for all! But this non change my problem. The first question and it's relative questions do not disappear. I leave the db structure in post.
– Kurtbain
Nov 21 '18 at 14:52
reading through the comments in question, I realize my understanding of your question was not correct. Let me know when you clickliceo scientifico
whether you want to show the third questionDi dove sei?
and its answers(relative questions?) only OR both second and third question with its answers and not show first question.
– Boban
Nov 21 '18 at 16:29
updated the answer, please see.
– Boban
Nov 21 '18 at 17:29
I would like that second question (and its answers) overwrite the first (and its answers). Sorry for delay
– Kurtbain
Nov 22 '18 at 9:09
Alright, The answer is updated for that. Please verify.
– Boban
Nov 22 '18 at 9:35
|
show 2 more comments
In your view:
...
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
you are setting only one value in each button. which is available as $_POST['btnScelta']
and that is used to render your last question.
Edit previous contents removed because they are not relevant to the question.
To render two questions pass two ids as the button value.
To remove the first question remove the two lines from your index.php
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
/* remove the following two lines the first question wont be rendered.*/
//$controllers->cercaDomanda(1);
//$controllers->cercaRisposta(1);
$controllers->cercaNuovoId(/*$id*/);
?>
Now make controller process two question display.
class Controller {
public function cercaNuovoId(/*$id*/){
// include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
// render previous question only if a value exists.
if ($result3) {
list($current, $previous) = explode(',', $result3);
$this->cercaDomanda($previous);
$this->cercaRisposta($previous);
}
// show the first question on first visit.
if (empty($current)){
$current = 1;
}
$reslt4 = $this->cercaDomanda($current);
$reslt5 = $this->cercaRisposta($current);
}
}
Now in the view make modification for button to have two values seperated by comma. current question id is available as $id from Controller::cercaRisposta()
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='{$rispost->id_domanda_successiva},{id}'>$rispost->risposta</button>
</td>";
}
?>
</form>
you can also pass the previous question id by changing form's action property with a query like index.php?previous=$id
.
Thanks for all! But this non change my problem. The first question and it's relative questions do not disappear. I leave the db structure in post.
– Kurtbain
Nov 21 '18 at 14:52
reading through the comments in question, I realize my understanding of your question was not correct. Let me know when you clickliceo scientifico
whether you want to show the third questionDi dove sei?
and its answers(relative questions?) only OR both second and third question with its answers and not show first question.
– Boban
Nov 21 '18 at 16:29
updated the answer, please see.
– Boban
Nov 21 '18 at 17:29
I would like that second question (and its answers) overwrite the first (and its answers). Sorry for delay
– Kurtbain
Nov 22 '18 at 9:09
Alright, The answer is updated for that. Please verify.
– Boban
Nov 22 '18 at 9:35
|
show 2 more comments
In your view:
...
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
you are setting only one value in each button. which is available as $_POST['btnScelta']
and that is used to render your last question.
Edit previous contents removed because they are not relevant to the question.
To render two questions pass two ids as the button value.
To remove the first question remove the two lines from your index.php
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
/* remove the following two lines the first question wont be rendered.*/
//$controllers->cercaDomanda(1);
//$controllers->cercaRisposta(1);
$controllers->cercaNuovoId(/*$id*/);
?>
Now make controller process two question display.
class Controller {
public function cercaNuovoId(/*$id*/){
// include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
// render previous question only if a value exists.
if ($result3) {
list($current, $previous) = explode(',', $result3);
$this->cercaDomanda($previous);
$this->cercaRisposta($previous);
}
// show the first question on first visit.
if (empty($current)){
$current = 1;
}
$reslt4 = $this->cercaDomanda($current);
$reslt5 = $this->cercaRisposta($current);
}
}
Now in the view make modification for button to have two values seperated by comma. current question id is available as $id from Controller::cercaRisposta()
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='{$rispost->id_domanda_successiva},{id}'>$rispost->risposta</button>
</td>";
}
?>
</form>
you can also pass the previous question id by changing form's action property with a query like index.php?previous=$id
.
In your view:
...
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
you are setting only one value in each button. which is available as $_POST['btnScelta']
and that is used to render your last question.
Edit previous contents removed because they are not relevant to the question.
To render two questions pass two ids as the button value.
To remove the first question remove the two lines from your index.php
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
/* remove the following two lines the first question wont be rendered.*/
//$controllers->cercaDomanda(1);
//$controllers->cercaRisposta(1);
$controllers->cercaNuovoId(/*$id*/);
?>
Now make controller process two question display.
class Controller {
public function cercaNuovoId(/*$id*/){
// include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
// render previous question only if a value exists.
if ($result3) {
list($current, $previous) = explode(',', $result3);
$this->cercaDomanda($previous);
$this->cercaRisposta($previous);
}
// show the first question on first visit.
if (empty($current)){
$current = 1;
}
$reslt4 = $this->cercaDomanda($current);
$reslt5 = $this->cercaRisposta($current);
}
}
Now in the view make modification for button to have two values seperated by comma. current question id is available as $id from Controller::cercaRisposta()
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='{$rispost->id_domanda_successiva},{id}'>$rispost->risposta</button>
</td>";
}
?>
</form>
you can also pass the previous question id by changing form's action property with a query like index.php?previous=$id
.
edited Nov 21 '18 at 17:27
answered Nov 21 '18 at 11:25


BobanBoban
314
314
Thanks for all! But this non change my problem. The first question and it's relative questions do not disappear. I leave the db structure in post.
– Kurtbain
Nov 21 '18 at 14:52
reading through the comments in question, I realize my understanding of your question was not correct. Let me know when you clickliceo scientifico
whether you want to show the third questionDi dove sei?
and its answers(relative questions?) only OR both second and third question with its answers and not show first question.
– Boban
Nov 21 '18 at 16:29
updated the answer, please see.
– Boban
Nov 21 '18 at 17:29
I would like that second question (and its answers) overwrite the first (and its answers). Sorry for delay
– Kurtbain
Nov 22 '18 at 9:09
Alright, The answer is updated for that. Please verify.
– Boban
Nov 22 '18 at 9:35
|
show 2 more comments
Thanks for all! But this non change my problem. The first question and it's relative questions do not disappear. I leave the db structure in post.
– Kurtbain
Nov 21 '18 at 14:52
reading through the comments in question, I realize my understanding of your question was not correct. Let me know when you clickliceo scientifico
whether you want to show the third questionDi dove sei?
and its answers(relative questions?) only OR both second and third question with its answers and not show first question.
– Boban
Nov 21 '18 at 16:29
updated the answer, please see.
– Boban
Nov 21 '18 at 17:29
I would like that second question (and its answers) overwrite the first (and its answers). Sorry for delay
– Kurtbain
Nov 22 '18 at 9:09
Alright, The answer is updated for that. Please verify.
– Boban
Nov 22 '18 at 9:35
Thanks for all! But this non change my problem. The first question and it's relative questions do not disappear. I leave the db structure in post.
– Kurtbain
Nov 21 '18 at 14:52
Thanks for all! But this non change my problem. The first question and it's relative questions do not disappear. I leave the db structure in post.
– Kurtbain
Nov 21 '18 at 14:52
reading through the comments in question, I realize my understanding of your question was not correct. Let me know when you click
liceo scientifico
whether you want to show the third question Di dove sei?
and its answers(relative questions?) only OR both second and third question with its answers and not show first question.– Boban
Nov 21 '18 at 16:29
reading through the comments in question, I realize my understanding of your question was not correct. Let me know when you click
liceo scientifico
whether you want to show the third question Di dove sei?
and its answers(relative questions?) only OR both second and third question with its answers and not show first question.– Boban
Nov 21 '18 at 16:29
updated the answer, please see.
– Boban
Nov 21 '18 at 17:29
updated the answer, please see.
– Boban
Nov 21 '18 at 17:29
I would like that second question (and its answers) overwrite the first (and its answers). Sorry for delay
– Kurtbain
Nov 22 '18 at 9:09
I would like that second question (and its answers) overwrite the first (and its answers). Sorry for delay
– Kurtbain
Nov 22 '18 at 9:09
Alright, The answer is updated for that. Please verify.
– Boban
Nov 22 '18 at 9:35
Alright, The answer is updated for that. Please verify.
– Boban
Nov 22 '18 at 9:35
|
show 2 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397027%2fphp-refreshing-only-data-in-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You want to look at MySQL's
ORDER BY
clause– Martin
Nov 20 '18 at 16:11
Possible duplicate of How can I reorder rows in sql database
– Martin
Nov 20 '18 at 16:11
No, i have postgresql and my problem isn't in db but in view. I call the questions and relative answers with id, there is no order.
– Kurtbain
Nov 21 '18 at 9:41
SQL is (partially) standard,
ORDER BY
is the same in MySQL and in PostgreSQL. "There is no order" - implement one!– DanFromGermany
Nov 21 '18 at 11:29
yes, but i don't have db problems. i have a problem of viewing. I would like the first question and it's relative answers disappear as the other.
– Kurtbain
Nov 21 '18 at 14:53