注意:数组到字符串转换

时间:2015-10-08 15:52:00

标签: php mysql

<?php
if(isset($_GET['search']))
{
    $search_record = $_GET['search'];

    $query = "SELECT * FROM semester_result,SUBJECT,std_reg WHERE semester_result.sub_id=subject.sub_id AND 
              semester_result.student_id = std_reg.student_id AND std_reg.roll_no='$search_record' ";

    $run = mysqli_query($conn,$query);

    if ($run->num_rows > 0)
    {
        while($row = mysqli_fetch_array($run))
        {
            $name = $row['fname'];
            $lname = $row['lname'];
            $sub=['subject_name'];
            echo $sub_id=['mid_mrks'];

?>

当我回显$name$lname时,它可以正常工作,但当我回显$sub$sub_id时,它会显示以下错误:

  

注意:第49行的C:\ wamp \ www \ semester \ content \ result.php中的数组到字符串转换。

2 个答案:

答案 0 :(得分:1)

该错误是由于将数组变量传递给echo()函数而不是字符串。

在您的示例中更改:

    $sub=['subject_name'];

为:

    $sub=$row['subject_name']; 

将解决问题。

答案 1 :(得分:1)

这个怎么样?

$name = $row['fname'];
$lname = $row['lname'];
$sub = $row['subject_name'];
echo $sub_id = $row['mid_mrks'];

我想你忘记了$row

前的['subject_name']