How do I use a single variable to update multiple rows in a POSTGRESQL table using PHP?












0















So my current table will look something like this:



CREATE TABLE "PDPC".consideration (
consideration_no bigint NOT NULL DEFAULT nextval('"PDPC".consideration_consideration_no_seq'::regclass),
question character varying(10000) COLLATE pg_catalog."default",
answer character varying(10000) COLLATE pg_catalog."default",
code_no bigint,
dg_fkey bigint,
CONSTRAINT consideration_no PRIMARY KEY (consideration_no),
CONSTRAINT dg_fkey FOREIGN KEY (dg_fkey)
REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION ) WITH (
OIDS = FALSE ) TABLESPACE pg_default;

ALTER TABLE "PDPC".consideration
OWNER to postgres;


My web page will display all the questions and answers in a single form. How will I go go about creating an UPSERT statement that will update the database accordingly using the variable $answer? I'm currently thinking of using a while loop, but it does not seem to be working. enter image description here



Current code that displays the questions and answers:



while($row = $stmt->fetch()){
// Retrieve individual field value
$question = $row["question"];
$answer = $row["answer"];




?>
<form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
<div class="form-group <?php echo (!empty($answer_err)) ? 'has-error' : ''; ?>">
<label><?php echo $question ?></label>
<input type="text" name="answer" class="form-control" value="<?php echo $answer; ?>">
<span class="help-block"><?php echo $answer_err;?></span>
</div>

<input type="hidden" name="dg_no" value="<?php echo $dg_no; ?>"/>
<?php








share







New contributor




Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    So my current table will look something like this:



    CREATE TABLE "PDPC".consideration (
    consideration_no bigint NOT NULL DEFAULT nextval('"PDPC".consideration_consideration_no_seq'::regclass),
    question character varying(10000) COLLATE pg_catalog."default",
    answer character varying(10000) COLLATE pg_catalog."default",
    code_no bigint,
    dg_fkey bigint,
    CONSTRAINT consideration_no PRIMARY KEY (consideration_no),
    CONSTRAINT dg_fkey FOREIGN KEY (dg_fkey)
    REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION ) WITH (
    OIDS = FALSE ) TABLESPACE pg_default;

    ALTER TABLE "PDPC".consideration
    OWNER to postgres;


    My web page will display all the questions and answers in a single form. How will I go go about creating an UPSERT statement that will update the database accordingly using the variable $answer? I'm currently thinking of using a while loop, but it does not seem to be working. enter image description here



    Current code that displays the questions and answers:



    while($row = $stmt->fetch()){
    // Retrieve individual field value
    $question = $row["question"];
    $answer = $row["answer"];




    ?>
    <form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
    <div class="form-group <?php echo (!empty($answer_err)) ? 'has-error' : ''; ?>">
    <label><?php echo $question ?></label>
    <input type="text" name="answer" class="form-control" value="<?php echo $answer; ?>">
    <span class="help-block"><?php echo $answer_err;?></span>
    </div>

    <input type="hidden" name="dg_no" value="<?php echo $dg_no; ?>"/>
    <?php








    share







    New contributor




    Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      So my current table will look something like this:



      CREATE TABLE "PDPC".consideration (
      consideration_no bigint NOT NULL DEFAULT nextval('"PDPC".consideration_consideration_no_seq'::regclass),
      question character varying(10000) COLLATE pg_catalog."default",
      answer character varying(10000) COLLATE pg_catalog."default",
      code_no bigint,
      dg_fkey bigint,
      CONSTRAINT consideration_no PRIMARY KEY (consideration_no),
      CONSTRAINT dg_fkey FOREIGN KEY (dg_fkey)
      REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION ) WITH (
      OIDS = FALSE ) TABLESPACE pg_default;

      ALTER TABLE "PDPC".consideration
      OWNER to postgres;


      My web page will display all the questions and answers in a single form. How will I go go about creating an UPSERT statement that will update the database accordingly using the variable $answer? I'm currently thinking of using a while loop, but it does not seem to be working. enter image description here



      Current code that displays the questions and answers:



      while($row = $stmt->fetch()){
      // Retrieve individual field value
      $question = $row["question"];
      $answer = $row["answer"];




      ?>
      <form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
      <div class="form-group <?php echo (!empty($answer_err)) ? 'has-error' : ''; ?>">
      <label><?php echo $question ?></label>
      <input type="text" name="answer" class="form-control" value="<?php echo $answer; ?>">
      <span class="help-block"><?php echo $answer_err;?></span>
      </div>

      <input type="hidden" name="dg_no" value="<?php echo $dg_no; ?>"/>
      <?php








      share







      New contributor




      Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      So my current table will look something like this:



      CREATE TABLE "PDPC".consideration (
      consideration_no bigint NOT NULL DEFAULT nextval('"PDPC".consideration_consideration_no_seq'::regclass),
      question character varying(10000) COLLATE pg_catalog."default",
      answer character varying(10000) COLLATE pg_catalog."default",
      code_no bigint,
      dg_fkey bigint,
      CONSTRAINT consideration_no PRIMARY KEY (consideration_no),
      CONSTRAINT dg_fkey FOREIGN KEY (dg_fkey)
      REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION ) WITH (
      OIDS = FALSE ) TABLESPACE pg_default;

      ALTER TABLE "PDPC".consideration
      OWNER to postgres;


      My web page will display all the questions and answers in a single form. How will I go go about creating an UPSERT statement that will update the database accordingly using the variable $answer? I'm currently thinking of using a while loop, but it does not seem to be working. enter image description here



      Current code that displays the questions and answers:



      while($row = $stmt->fetch()){
      // Retrieve individual field value
      $question = $row["question"];
      $answer = $row["answer"];




      ?>
      <form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
      <div class="form-group <?php echo (!empty($answer_err)) ? 'has-error' : ''; ?>">
      <label><?php echo $question ?></label>
      <input type="text" name="answer" class="form-control" value="<?php echo $answer; ?>">
      <span class="help-block"><?php echo $answer_err;?></span>
      </div>

      <input type="hidden" name="dg_no" value="<?php echo $dg_no; ?>"/>
      <?php






      postgresql php upsert





      share







      New contributor




      Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 5 mins ago









      RestiaRestia

      1




      1




      New contributor




      Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Restia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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
          });


          }
          });






          Restia is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f227061%2fhow-do-i-use-a-single-variable-to-update-multiple-rows-in-a-postgresql-table-usi%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








          Restia is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Restia is a new contributor. Be nice, and check out our Code of Conduct.













          Restia is a new contributor. Be nice, and check out our Code of Conduct.












          Restia is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • 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%2fdba.stackexchange.com%2fquestions%2f227061%2fhow-do-i-use-a-single-variable-to-update-multiple-rows-in-a-postgresql-table-usi%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

          Liste der Baudenkmale in Friedland (Mecklenburg)

          Single-Malt-Whisky

          Czorneboh