samedi 18 avril 2015

How to return two SQL tables in one result- Laravel

I want to return two SQL tables to single result array. I tried to use array_merge(), but it seems that I am missing an important point.

Here is a route '/' function

Route::get('/', function()
$items = get_items();
return View::make('posts')->withItems($items);

function get_items()

$sql = "select postlist.* from postlist order by desc ";
$items = DB::select($sql);
$sql1 = "select count ( as 'comments',,,commentlist.comment from postlist,commentlist where";
$items1 = DB::select($sql1);

$items = array_merge($items, $items1);

return $items;


Blade.php file where I retrieve records.

@if ($items)

<table class="bordered">
<tr><th>Icon</th><th>Title</th><th>Post</th><th>Name</th><th>Update Post </th><th>Delete Post </th><th>View Comments</th></tr>
@foreach ($items as $item)
<td><img class='photo' src='image/images.png' alt='photo' style="height:25px; width:35px;" ></td>
<td>{{{ $item->title }}} </td>
<td> {{{ $item->post }}} </td>
<td>{{{ $item->name }}}</td>
<td><a href="{{{ url("update_item/$item->id") }}}">Update</a></td>
<td><a href="{{{ url("delete_item_action/$item->id") }}}">Delete</a></td>
<td><a href="{{{ url("comments_item/$item->id") }}}">Comments</a></td>


<p>No items found.</p>

Aucun commentaire:

Enregistrer un commentaire