duanju9104 2017-03-27 14:39
浏览 43
已采纳

使用Codeigniter,程序运行不正常

Im trying (without success) to run my program using codeigniter:

Here is the program:

    <?php include('connect.php');

?>

<html>
<head>

    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</head>
    <body>

    <div class="container"> 
    <div class="row">
    <div class="col-md-12">



    <a href="estudiante.php"><button type="button" class="btn btn-success">AGREGAR</button></a><br /><br />
        <h2 align="center">TABLA:MATERIAS</h2>
        <input id="busqueda_tabla" type="text">
            <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
                <thead>
                    <th>id</th>
                    <th>Carrera</th>
                    <th>Nombre</th>
                    <th>Descripcion</th>
                    <th>Carga horaria (hs)</th>
                    <th>Accion</th>
                </thead>

    <?php

                $sql=mysql_query("SELECT s.*, c.nombre AS carrera FROM materias s LEFT JOIN carreras c ON s.carrera_id=c.id");//ESTA FUNCION ME AYUDA A ACOMODAR LAS CARRERAS EN LA COLUMNA "CARRERA" DE LA TABLA
                $i=1;
                    while($row=mysql_fetch_array($sql)){
                        echo "<tr>
                                <td>".$i."</td>
                                <td>".$row['carrera']."</td>
                                <td>".$row['nombre']."</td>
                                <td>".$row['descripcion']."</td>
                                <td>".$row['carga_horaria']."</td>
                                <td align='center'>
                                    <a href='editar.php?editar=1&iden=".$row['id']."'><button type='button' class='btn btn-primary'>EDITAR</button></a> |
                                    <a href='borrar.php?borrar=1&iden=".$row['id']."'><button type='button' class='btn btn-danger'>BORRAR</button></a>
                                </td>
                        </tr>";
                        $i++;

                    }
                ?>


            </table>    

        </div>
        </div>
        </div>

    </body>



</html>

And i've tried this.. but i got some errors when i run it; This is my Codeigniter code:

My "view" file:

<?php include('header.php'); ?>

<?php include('footer.php'); ?>


    <div class="container"> 
    <div class="row">
    <div class="col-md-12">

        <h2 align="center">TABLA:MATERIAS</h2>
        <input id="busqueda_tabla" type="text">
            <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
                <thead>
                    <th>id</th>
                    <th>Carrera</th>
                    <th>Nombre</th>
                    <th>Descripcion</th>
                    <th>Carga horaria (hs)</th>
                    <th>Accion</th>
                </thead>


    <?php
        $i=1;
        foreach($records as $record) {

            echo "<tr>
                      <td>".$i."</td>
                      <td>".$record->carrera."</td>
                      <td>".$record->nombre."</td>
                      <td>".$record->descripcion."</td>
                      <td>".$record->carga_horaria."</td>
                      <td align='center'>
                         <a href='editar.php?editar=1&iden=".$record->id."'><button type='button' class='btn btn-primary'>EDITAR</button></a> |
                         <a href='borrar.php?borrar=1&iden=".$record->id."'><button type='button' class='btn btn-danger'>BORRAR</button></a>
                      </td>
                  </tr>";
        }
        $i++;
    ?>
    </table>

        </div>
        </div>
        </div>

Here is my Crudmodel file:

      <?php

    Class Crudmodel extends CI_Model{

        public function getRecords(){

            $this->db->select('s.*, c.nombre AS carrera')
                     ->from('materias s')
                     ->join('carreras c', 's.carrera_id = c.id', 'left');
            $q = $this->db->get();

            if($q -> num_rows() > 0){

                return $q->result();
            }

            return false;

        }

    }


?>

And the controller file:

    <?php

    class Home extends CI_Controller{

        public function index(){
            $this->load->model('Crudmodel');
            $data['records'] = $this->Crudmodel->getRecords();
            $this->load->view('home', $data['records']);

        }
    }
?>

I dont know what's going on, i dont get it :/. These are the errors:

https://i.gyazo.com/607303edcd861d0a2257611c925f3e6e.png
https://i.gyazo.com/eb9d833bf5d0818db2906ec1447550c0.png
https://i.gyazo.com/c5bb77d50315888a375a1e775a5ad68c.png

Hope you can help me

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置