• <bdo id='IuRIF'></bdo><ul id='IuRIF'></ul>
    <i id='IuRIF'><tr id='IuRIF'><dt id='IuRIF'><q id='IuRIF'><span id='IuRIF'><b id='IuRIF'><form id='IuRIF'><ins id='IuRIF'></ins><ul id='IuRIF'></ul><sub id='IuRIF'></sub></form><legend id='IuRIF'></legend><bdo id='IuRIF'><pre id='IuRIF'><center id='IuRIF'></center></pre></bdo></b><th id='IuRIF'></th></span></q></dt></tr></i><div id='IuRIF'><tfoot id='IuRIF'></tfoot><dl id='IuRIF'><fieldset id='IuRIF'></fieldset></dl></div>
    <legend id='IuRIF'><style id='IuRIF'><dir id='IuRIF'><q id='IuRIF'></q></dir></style></legend>

    <small id='IuRIF'></small><noframes id='IuRIF'>

      1. <tfoot id='IuRIF'></tfoot>
      2. php pdo 只从 mysql 获取一个值;等于变量的值

        时间:2023-10-05
        <legend id='tYofc'><style id='tYofc'><dir id='tYofc'><q id='tYofc'></q></dir></style></legend>

        <i id='tYofc'><tr id='tYofc'><dt id='tYofc'><q id='tYofc'><span id='tYofc'><b id='tYofc'><form id='tYofc'><ins id='tYofc'></ins><ul id='tYofc'></ul><sub id='tYofc'></sub></form><legend id='tYofc'></legend><bdo id='tYofc'><pre id='tYofc'><center id='tYofc'></center></pre></bdo></b><th id='tYofc'></th></span></q></dt></tr></i><div id='tYofc'><tfoot id='tYofc'></tfoot><dl id='tYofc'><fieldset id='tYofc'></fieldset></dl></div>

              <tfoot id='tYofc'></tfoot>
                <bdo id='tYofc'></bdo><ul id='tYofc'></ul>

                  <small id='tYofc'></small><noframes id='tYofc'>

                    <tbody id='tYofc'></tbody>
                  本文介绍了php pdo 只从 mysql 获取一个值;等于变量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经定义了变量 $row_id1(例如 $row_id1 = 1;)

                  I have defined variable $row_id1 (for example $row_id1 = 1;)

                  在 mysql 中,列名为 Number.

                  In mysql is column called Number.

                  想要选择列Number,如果列中存在$row_id,想要获取(获取,定义)值.实际想检查列 Number 中是否存在 $row_id 值.

                  Want to select the column Number and if in the column exists $row_id, want to get (fetch, define) the value. Actually want to check if in column Number exists $row_id value.

                  代码有什么问题?

                  $stmt = $db->prepare("SELECT Number FROM 2_1_journal WHERE Number = :Number1");
                  $stmt->bindParam(':Number1', $row_id1); //value from $_POST
                  $stmt->execute();
                  $Number1 = $stmt->fetchAll(PDO::FETCH_ASSOC); // seems here something is wrong
                  
                  echo $Number1 .' $Number1<br>';
                  

                  在输出中我得到数组 $Number1

                  In output I get Array $Number1

                  好像简单(愚蠢)的问题,但搜索了几个小时却没有解决方案

                  As if simple (stupid) question but searching for some hours and no solution

                  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                  更新代码

                  这部分与问题无关(仅供参考)

                  This part is not related to problem (only for information)

                  require($_SERVER['DOCUMENT_ROOT'] . "/_additionally_protected/session.class.php"); 
                  $session = new session();
                  // Set to true if using https
                  $session->start_session('_a', false);
                  
                  session_regenerate_id();
                  
                  //require($_SERVER['DOCUMENT_ROOT'].'/_additionally_protected/request_blocker.php');  //slow page load
                  
                  require($_SERVER['DOCUMENT_ROOT'].'/_measure_time_start.php');
                  
                  require($_SERVER['DOCUMENT_ROOT'].'/_additionally_protected/db_config.php');
                  header('Content-type: text/html; charset=utf8');
                  
                  require($_SERVER['DOCUMENT_ROOT'] . "/only_private/blackhole.php");
                  
                  ini_set('session.bug_compat_warn', 0);
                  ini_set('session.bug_compat_42', 0);
                  

                  这与问题有关(这里我从输入中获取值)

                  This is related to problem (here I get values from input)

                  if(get_magic_quotes_gpc())
                  $row_id1 = htmlspecialchars(stripslashes($_POST['row_id1']));
                  else
                  $row_id1 = htmlspecialchars($_POST['row_id1']);
                  echo $row_id1 .' row_id1 from $_POST<br>';
                  

                  连接到mysql

                  try {
                  $db = new PDO("mysql:host={$dbhost};dbname={$dbname};charset=utf8", $dbuser, $dbpass//, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
                  , array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
                  //echo "Connected to database"; // check for connection
                  }
                  catch(PDOException $ex) {
                  //echo "An Error occured!"; //user friendly message
                  //print "Error!: " . $ex->getMessage() . "<br/>";
                  //some_logging_function($ex->getMessage());
                  exit;
                  }
                  

                  这里我从 mysql 获取最后一行编号.后来我将数字+1 传递给 html 隐藏的 iput 字段.我的意思是在页面加载时我得到最后一个数字.如果用户点击按钮不执行代码.

                  Here I get last row number from mysql. Latter I pass the number+1 to html hidden iput field. I mean on page load I get last number. If user clicks on button do not execute the code.

                  //fetch last Number to pass to row_id and entry_id
                  if( !$_POST['register'] ) {
                  echo '!$_POST[register] <br>';
                  //+++++++++++++ now multiple PDO
                  
                  // Select table with query
                  $stmt = $db->query("
                  SELECT Number FROM 2_1_journal ORDER BY Number DESC LIMIT 1
                  ");
                  // Set fetching mode
                  $stmt->setFetchMode(PDO::FETCH_ASSOC);
                  // Assign $row as your key to access Table fields
                  foreach ($stmt as $row) :
                  echo $row['Number'] .' $row[Number] On page load (reload) get number of last row in   mysql; to pass to Entry ID and rowid<br>';
                  $_SESSION['last_number_from_mysql'] = $row['Number'];
                  endforeach;
                  }//if( !$_POST['register'] ) {
                  

                  会话(上)

                  这是给我带来问题的部分//从 DB 中获取 Number 以与行 ID(隐藏)进行比较.旨在决定是否需要记录新行或是否更新现有行.代码在 $_POST 上执行.所以必须定义$row_id(上面定义的)

                  This is the part that makes problem for me // Get Number from the DB latter to compare with row ID (hidden). Aim to decide if need to record new row or if to update existing. The code is executed on $_POST. So must define $row_id (defined above)

                  if( $_POST['register'] ) {
                  

                  如果用户只点击按钮然后执行代码

                  If user click on button only then execute the code

                  echo $row_id1 .' row_id1 before select Number where Number is $row_id1<br>';
                  

                  这是检查.我看到 row_id1 号;这意味着收到了号码.就在下面想用

                  This is to check. I see row_id1 number; That means that the number is received. And just below want to use it

                  $stmt = $db->prepare("SELECT Number FROM 2_1_journal WHERE Number = :Number1"); 
                  $stmt->bindParam(':Number1', $row_id1);
                  $stmt->execute();
                  echo $Number1 = $stmt->fetchColumn() .' $Number1<br>';
                  

                  仅当点击按钮 2 次时此回显

                  This echo only if 2 times click on button

                  这里是html输入

                  <input type="tex" name="row_id1" id="row_id1" value="
                  <?php
                  //if( ($_POST['register']) === 'Save draft' ) {
                  //echo $_POST['row_id1'];
                  /
                • <tfoot id='k9Z63'></tfoot>

                  <small id='k9Z63'></small><noframes id='k9Z63'>

                  <legend id='k9Z63'><style id='k9Z63'><dir id='k9Z63'><q id='k9Z63'></q></dir></style></legend>
                        <tbody id='k9Z63'></tbody>

                          <bdo id='k9Z63'></bdo><ul id='k9Z63'></ul>
                          <i id='k9Z63'><tr id='k9Z63'><dt id='k9Z63'><q id='k9Z63'><span id='k9Z63'><b id='k9Z63'><form id='k9Z63'><ins id='k9Z63'></ins><ul id='k9Z63'></ul><sub id='k9Z63'></sub></form><legend id='k9Z63'></legend><bdo id='k9Z63'><pre id='k9Z63'><center id='k9Z63'></center></pre></bdo></b><th id='k9Z63'></th></span></q></dt></tr></i><div id='k9Z63'><tfoot id='k9Z63'></tfoot><dl id='k9Z63'><fieldset id='k9Z63'></fieldset></dl></div>