duanjiao8007 2016-05-20 13:50 采纳率: 100%
浏览 107
已采纳

我的代码中的语句绑定参数有错误

In My code i am using a prepare statement using bind_result. In the following code i access all values on the carmake table. In that when I am going to access the admin name it gives me the error "Call to a member function bind_param() on a non-object". I have used this code previously. i used get_result at that time and it worked fine, but when I used bind_result it gives an error

  <!DOCTYPE html>
        <html>
        <head>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script type="text/javascript">


        </script>

        <?php 
        session_start();

        if(isset($_SESSION['username1']))
        {

            include("../config/database.php");

            if(isset($_GET["page"])) 
                { 
                    $page  = $_GET["page"];
                    $rows_per_page = 10; 
                } 
                else 
                { 
                    $page=1;
                 }
                                $start_from = ($page * 10) -10;     
                                $limit = ($page * 10);


            $query=$conn->prepare("SELECT   makeid,name,status,creation_date_and_time,created_by FROM carmake ORDER BY makeid desc LIMIT $start_from,10");
            $query->execute();
            $query->bind_result($makeid,$name,$status,$creation_date_and_time,$created_by);
            //$result=$query->get_result();

        ?>

        <?php

            ?>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
                              <tr>
                                <th width="6%" align="center" class="tbl_back"> Id</th>


                                <th width="12%" align="center" class="tbl_back">Name</th>

                                <th width="12%" align="center" class="tbl_back">Created by</th>

                                <th width="12%" align="center" class="tbl_back">Status</th>
                                <th width="12%" align="center" class="tbl_back">Edit</th>
                                <th width="12%" align="center" class="tbl_back">Delete</th>
                                </tr> 
        <?php

                                //$i = 0;

                while($query->fetch())
                {
                        /* Construct Data */

                     ?>
                <?php

                    /*$serviceid=$data['servicetype'];
                    $query2="select * FROM tblservicemaster where serviceid='$serviceid'";
                    $result2 = mysql_query($query2,$conn) or die(mysql_error());
                    $leadservice=mysql_fetch_array($result2);*/
                ?>
                     <tr>

                        <td class="tbl_back1"><?php echo $makeid ?></td>
                         <td class="tbl_back1"><?php echo $name ?></td> 

                           <td class="tbl_back1"> <?php
                            $idd=$created_by;
                           $query1=$conn->prepare("select name,adminid from  admintable where adminid=?");
                            $query1->bind_param("i",$idd);  
                            $query1->execute(); 

                            $query1->bind_result($name,$adminid);
                            //$query1->store_result();

                            $query1->fetch();

                          /* $query1="select name from  admintable where id=".$data[4];
                           $result1=mysql_query($query1) or die(mysql_error());
                           $data1=mysql_fetch_array($result1);*/

                          echo $name; 

                          ?> </td> 




                        <td class="tbl_back1"><?php if($status==1){echo "Enabled";}if($status==0){echo "Disabled";} ?></td>         

                        <td class="celledit"><a href="edit_carmakepages.php?id=<?php echo $makeid; ?>"><center><img src="images/editsign.jpg"/></center> </a></td> 
                        <td class="celldelete"><a href="javascript:del_topic(<?php echo makeid; ?>)"><center><img src="images/deletesign.jpg"/></center> </a></td>





                        <?php   
                            //$i++; 
                        ?>
                        </tr>
                    </tr>
                <?php  

                } // end while


                /*else
                {   
        ?>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
                           <tr>
                                <th width="6%" align="center" class="tbl_back"> Id</th>


                                <th width="12%" align="center" class="tbl_back">Name</th>

                                <th width="12%" align="center" class="tbl_back">Created by</th>

                                <th width="12%" align="center" class="tbl_back">Status</th>
                                <th width="12%" align="center" class="tbl_back">Edit</th>
                                <th width="12%" align="center" class="tbl_back">Delete</th>
                                </tr> 

                    <tr>
                        <td colspan="15" align="center" style=" color:red"  class="tbl_back12">
                        No Record Found
                        <!--<h4 class="aligncenter">No Record Found</h4>-->
                        </td>
                    </tr>
                    <?php
                    }*/
                    ?>

        </tbody>
        </table>
        <?php } ?>
        </html>
  • 写回答

2条回答 默认 最新

  • drxdai15012937753 2016-05-20 14:21
    关注

    Try completely changing the while loop

    while($query->fetch()){
    $row[] = array('makeid' => $makeid, 'status' => $status, 'creation_date_and_time' => $creation_date_and_time, 'created_by' => $created_by);
    } //end while
    

    then change the while loop in its current form to a foreach and assign $iss the value of the current iteration of the arrays 'created_by' value like this:

    foreach($row as $resultsFromArray){
                        /* Construct Data */
    
                     ?>
                <?php
    
                    /*$serviceid=$data['servicetype'];
                    $query2="select * FROM tblservicemaster where serviceid='$serviceid'";
                    $result2 = mysql_query($query2,$conn) or die(mysql_error());
                    $leadservice=mysql_fetch_array($result2);*/
                ?>
                     <tr>
    
                        <td class="tbl_back1"><?php echo $makeid ?></td>
                         <td class="tbl_back1"><?php echo $name ?></td> 
    
                           <td class="tbl_back1"> <?php
                            $idd=$resultsFromArray['created_by']; //<--- Notice the change here
                           $query1=$conn->prepare("select name,adminid from  admintable where adminid=?");
                            $query1->bind_param("i",$idd);  
                            $query1->execute(); 
    
                            $query1->bind_result($name,$adminid);
                            //$query1->store_result();
    
                            $query1->fetch();
    
                          /* $query1="select name from  admintable where id=".$data[4];
                           $result1=mysql_query($query1) or die(mysql_error());
                           $data1=mysql_fetch_array($result1);*/
    
                          echo $name; 
    
                          ?> </td> 
    
    
    
    
                        <td class="tbl_back1"><?php if($status==1){echo "Enabled";}if($status==0){echo "Disabled";} ?></td>         
    
                        <td class="celledit"><a href="edit_carmakepages.php?id=<?php echo $makeid; ?>"><center><img src="images/editsign.jpg"/></center> </a></td> 
                        <td class="celldelete"><a href="javascript:del_topic(<?php echo makeid; ?>)"><center><img src="images/deletesign.jpg"/></center> </a></td>
    
    
    
    
    
                        <?php   
                            //$i++; 
                        ?>
                        </tr>
                    </tr>
                <?php  
    
                }// end foreach
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog