Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从数据库中检索数据并在laravel中显示?_Php_Sql_Laravel - Fatal编程技术网

Php 如何从数据库中检索数据并在laravel中显示?

Php 如何从数据库中检索数据并在laravel中显示?,php,sql,laravel,Php,Sql,Laravel,我想用编辑和删除按钮在表中显示laravel中每条记录的数据 我必须在现有页面中显示它 管理员控制器 <?php namespace App\Http\Controllers\Admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Category; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facade

我想用编辑和删除按钮在表中显示laravel中每条记录的数据

我必须在现有页面中显示它

管理员控制器

<?php

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Category;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;

class AdminController extends Controller
{
    public function show()
    {
       return view('admin/admin');
    }

    public function addCategory()
    {
        $category=new Category;
        $category->category_name = Input::get('category');
        $category->save();
        return view('admin/admin');
    }
}
admin.blade.php

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <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">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        .bod{
            background-color:#f8f8f8 ;
            border-shadow: 5px 10px 20px white inset;
            border-width:5px;
            margin-top:-12px;
        }
        .h1{
            font-family:"Book Antiqua";
            font-size: 90px;
            color: red;
            text-align: center;
        }
        div {
            border-radius: 5px;
            /*background-color: #f2f2f2;*/
            /*background-color: #7CA8C1  ;*/
            padding: 20px;
            position: relative;
            border:2px solid white;
            height: 200px;
            width: 50%;
            margin-left: 50px;
        }
        .txt{
            width: 150px;
            height:25px;
            border: 2px solid white;
        }
        .btn{
            width: 100px;
            height:28px;
            font-weight: bold;
            border: 2px solid white;
        }
    </style>
</head>
<body class="bod">
<h1 class="h1">Admin</h1>
<div align="left">

    <form action="{{ route('addCategory') }}" method="get">
        {{ csrf_field() }}
        <label for="category" style="font-family: 'Book Antiqua';font-size: 48px;color: #9999FF;">Category</label> <br/>
        <table class="table ">
            <tr>
                <td align="center"><input class="txt" type="text" name="category" id="category" placeholder="Enter the Category" ></td>
                <td align="center"></td>
                <td align="center"> <input type="submit" name="add" id="add" value="ADD" class="btn"></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>
我想在“管理员”页面中显示管理员添加的所有类别,并使用“更新和删除”按钮。如何实现这一点?

地址类型和学生类型是您的创建类型

您忘记创建一个表Student\u tbl来携带插入数据

你可以参考这个演示

create type Address_type as object ( 
    hno char(4), 
    street varchar2(10), 
    city varchar2(10) 
);

create type Student_type as object ( 
    sno char(4), 
    sname varchar2(10), 
    adddress Address_type 
);

CREATE TABLE Student_tbl(
    V1 Student_type
);

insert into Student_tbl values (Student_type('4567',
                                             'Shan',
                                              Address_type('30','aaa','bbb')
                                             )
                               );
编辑

如果你想得到你的客户类型,比如地址类型,你可以这样做

select t.SNO,
       t.SNAME,
       t.adddress.hno,
       t.adddress.street,
       t.adddress.city
from Student_tbl t

这里是编码创建student类型的表student\u tbl;很好,谢谢,但是我们不能用select*来获取输出吗?为什么是这样?你可以看到。简单来说,您可以使用自定义类型字段作为对象,您发布的代码可以正常工作。也就是说,记录被插入到表中。因此,要么您运行的代码与您在此处发布的代码不同,要么您没有正确运行它。无论哪种方式,只有你能知道你做了什么或没有做什么。
select t.SNO,
       t.SNAME,
       t.adddress.hno,
       t.adddress.street,
       t.adddress.city
from Student_tbl t