如何在php中为文本框设置数组数据 [英] how to set array data for the textbox in php

查看:52
本文介绍了如何在php中为文本框设置数组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**我有home.php文件和superLec.php文件.用户可以输入 studentUniversityId 并单击提交"按钮.我想显示 studentName 文本框和 lecturerName 文本框的特定数据.我想将数据作为数组传递.如何为文本框值设置数组数据.请任何人帮助我.**.

**I have home.php file and superLec.php file. user can enter studentUniversityId and click on the submit button. particular data i want to show studentName textbox and lecturerName textbox. I want to pass data as a array. How to set array data for textbox value.Please any one help me. **.

home.php

<?php 
session_start();
    include_once 'include/class.supervisor.php';
    $supervisor = new Supervisor();

    if (isset($_POST['submit'])) { 
        extract($_POST);        
        $autofill = $supervisor->check_auto_fill($studentUniversityId);
       /* if ($autofill) {
            // Registration Success
           header("location:homeLecturer.php");
        } else {
            // Registration Failed
            echo 'Wrong username or password';
        }*/
    }
    ?>
    <form action="" method="post">

            <label for="studentID">Student ID</label>
            <input type="text" name="studentUniversityId" id="studentID" placeholder="studentID">
            <!--input type="submit" id="autoFill" name="autoFill" value="Auto Fill"><br><br>
            <input class="btn" type="submit" name="submit" value="Auto Fill"-->

            <label for="studentName">Student Name</label>
            <input type="text" id="studentName" name="studentName" value = "<?php echo print_r($autofill);?>" placeholder="Student Name"><br><br>

            <label for="lecturerName">Supervisor Name</label>
            <input type="text" id="lecturerName" name="lecturerName" value = "<?php echo ($lecturerName) ;?>" placeholder="Supervisor Name"><br><br>

         <input type="submit" id="submit" name="submit" value="submit">  


        </form>

**这是我的php文件.我想要传递home.php文件的数组值.谁能帮助我.**

**This is my php file. I want pass array values for the home.php file. can any one help me pls. **

superLe.php

public function check_auto_fill($studentUniversityId){

    $query = "SELECT supervisor.lecturerName, supervisee.studentName, supervisee.studentUniversityId FROM supervisee, supervisor WHERE supervisee.lecturerId = supervisor.lecturerId AND supervisee.studentUniversityId = '$studentUniversityId' ";

    $result = $this->db->query($query) or die($this->db->error);
    $supervisor_data = $result->fetch_array(MYSQLI_ASSOC);
    $arr = array("lecturerName", "studentName", "studentName");
    return $arr;

}

推荐答案

根据我的了解和理解(如果没有,请原谅),您想填充文本字段 studentName lecturerName 及其各自的值.对我来说,除了一件事之外,您的代码看起来是正确的.您需要删除行

From what I see and understand (please excuse if I don't), you want to populate the text fields studentName and lecturerName with their respective values. To me, you code looks correct except one thing. You need to drop the line

$arr = array("lecturerName", "studentName", "studentName");

来自 superLe.php .线

$supervisor_data = $result->fetch_array(MYSQLI_ASSOC);

已经返回一个关联数组,您可以在文件 home.php 中的变量 $ autofill 中将其用作 $ autofill ['studentName'] $ autofill ['lecturerName'] .

already returns an associative array, which you can use in the variable $autofill in file home.php as $autofill['studentName'] or $autofill['lecturerName'].

这篇关于如何在php中为文本框设置数组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆