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();
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示