dqzow3859 2015-01-12 19:36
浏览 49
已采纳

如何在表单加载过程中在PHP中的每个文本框中传输多个值

I have a little SQL Commands Here

Databasename:Numbers

select * from tblstart where id = 1
output = 10
select * from tblstart where id = 2
output = 20
select * from tblstart where id = 3
output = 30
select * from tblstart where id = 4
output = 40
select * from tblstart where id = 5
output = 50

How can i transfer this output in textbox during Page Load

<input type="text" name="OutputOf10"><br>
<input type="text" name="OutputOf20"><br>
<input type="text" name="OutputOf30"><br>
<input type="text" name="OutputOf40"><br>
<input type="text" name="OutputOf50"><br>

Any help would be appreciated TY

Here is the code so far but im getting errors

Here is the php code(Updated)

 <?php 

$host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'poi';
try {
  $pdo = new PDO('mysql:host='.$host.';dbname='.$db_name.'', $db_user, $db_pass);
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $stmt = $pdo->prepare('SELECT COUNT(name) FROM tblmarker WHERE name = (Robbery)');
  $stmt->execute(array('id'));

  $result = $stmt->fetchAll();

  if ( count($result) ) { 
    foreach($result as $row) {
      $OutputOf10 = $row['Name'];
      echo '<input type="text" name="OutputOf10" value="'.$OutputOf10.'"><br>';
    }   
  } else {
    echo "No rows returned.";
  }
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}
?>
  • 写回答

1条回答 默认 最新

  • doswy02440 2015-01-12 19:53
    关注

    You are missing quite a bit of information that would allow us to better help you.

    Here's a start:

    <?php 
    
    $host = 'localhost';
    $db_user = 'root';
    $db_pass = '';
    $db_name = 'poi';
    try {
      $pdo = new PDO('mysql:host='.$host.';dbname='.$db_name.'', $db_user, $db_pass);
      $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $stmt = $pdo->prepare('SELECT name from tblmarker where id = 112"');
      $stmt->execute(array('OutputOf10' => $id));
    
      $result = $stmt->fetchAll();
    
      if ( count($result) ) { 
        foreach($result as $row) {
          $OutputOf10 = $row['name'];
          echo "<input type="text" name="OutputOf10" id="OutputOf10" value='".$OutputOf10."' ";
        }   
      } else {
        echo "No rows returned.";
      }
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    ?> 
    
    <input type="text" name="OutputOf10" value="<?php echo $Outputof10 ?>"><br>
    

    To support update:

    <?php 
    $id = 112;
    $host = 'localhost';
    $db_user = 'root';
    $db_pass = '';
    $db_name = 'poi';
    try {
      $pdo = new PDO('mysql:host='.$host.';dbname='.$db_name.'', $db_user, $db_pass);
      $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $stmt = $pdo->prepare('SELECT * FROM tblmarker WHERE id = :id');
      $stmt->execute(array('id' => $id));
    
      $result = $stmt->fetchAll();
    
      if ( count($result) ) { 
        foreach($result as $row) {
          $OutputOf10 = $row['name'];
          echo '<input type="text" name="OutputOf10" value="'.$OutputOf10.'"><br>';
        }   
      } else {
        echo "No rows returned.";
      }
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)