【发布时间】:2015-07-06 07:56:37
【问题描述】:
您好,我有一个像这样迭代的表
<form method="get" action="search">
<table class="bordered">
<thead>
<tr><th>No.</th><th>Post Username</th><th>Post Title</th><th>Post</th><th>Delete This post</th><td>Update This Post</td></tr>
</thead>
<tbody>
@foreach ($posts as $post)
<tr>
<td>{{{ $post->id }}}</td>
<td>{{{ $post->post_username }}}</td>
<td>{{{ $post->post_title }}}</td>
<td>{{{ $post->post_message }}}</td>
<td>
<form method="post" action="{{{ url('delete_post_action') }}}">
<input type="submit" value="{{ $post->id }}">Delete</td>
</form>
</td>
<td><button name="update" value="{{ $post->id }}">Update</button></td>
</tr>
@endforeach
</tbody>
</table>
</form>
连接到这条路线。
Route::post('delete_post_action', function()
{
$sql = "select * from posts";
$current_posts = DB::select($sql);
$results=$current_posts;
return View::make('pages.home')->withposts($results);
});
function delete_item($id)
{
$id = $post->id;
$sql = "delete from posts where id = ?";
DB::delete($sql, array($id));
}
我不知道为什么它不起作用。它按预期刷新页面并更新表格。但它不会删除任何行!
【问题讨论】:
-
但是我将如何引用 id?我试过 $id = $post->id;但没有骰子。
-
据我所知,您没有正确引用 id。
-
对不起我的无知,但我不确定你的意思?我该怎么做?它会在函数中去哪里?我在这里遇到了一些严重的斗争。
标签: php arrays database sqlite laravel-4