dongshi9719 2016-01-27 16:09
浏览 16

我怎样才能得到另一张桌子的价格

I have a table products:

Products
-id
-seller_id
-category_id
-product_name

and also a Product_options table:

Product_options 
-id
-product_id
-size_name
-width
-height
-quantity
-price

I have here a function show which is a function where you can view the products in home.blade.php:

public function show($id)
{  
    $likes = DB::SELECT(DB::RAW("SELECT count(*) as like_count FROM `likes` WHERE product_id = $id"));

    $products = DB::SELECT(DB::RAW("SELECT p.id as product_id, p.name as product_name, p.price, p.description, p.image, c.id as category_id, c.name as category_name FROM products p, categories c WHERE p.category_id = c.id AND p.id = $id"));

    $product_options = DB::SELECT(DB::RAW("SELECT po.pricee FROM product_options po, products p WHERE p.id = po.product_id AND product_id = $product_id "));

    return View::make('products.show', ['products' => $products, 'like_count' => $likes[0]->like_count,'product_options'=>$product_options]);

Home.blade.php

if(isset($products) && $products) {
    foreach ($products as $product => $value) {

        $new_description = strlen($products[$product]->description) > 50 ? substr($products[$product]->description,0,50)."..." : $products[$product]->description;

        echo '
            <div class="col-sm-6 col-md-4">
                <div class="thumbnail" >
                    <div class="pull-right">';
                        if(Auth::check()) {
                            if(Auth::user()->id == $products[$product]->seller_id) {
                                echo '<a href="'.URL::to('product/editproduct', [$products[$product]->product_id]).'">
                                <span class="glyphicon glyphicon-edit"></span>
                                </a>';

                            }
                            else {
                                echo '<a href="">&nbsp;</a>';
                            }
                        }

                        echo    '</div><a href="'.URL::route('categories', [$products[$product]->category_name]).'"><h4 class="text-center"><span class="label label-info">'.$products[$product]->category_name.'</span></h4></a>

                            <div class="img-container-background">
                                <div class="img-container">

                                    <a href="'.URL::to('product/'.$products[$product]->product_id).'"> <img src="'.URL::asset('assets/images/uploads/'.$products[$product]->image).'" class="img-responsive" /></a>
                                </div>
                            </div>

                            <div class="caption">
                                <div class="row">
                                    <div class="col-md-6 col-xs-6">
                                        <h3 style="font-size:20px">'.$products[$product]->product_name.'</h3>
<span>By <a href="">'.$products[$product]->seller_name.'</a></span>

How I can get the price of product_options to view the price in my home blade?

  • 写回答

1条回答 默认 最新

  • dongzao9044 2016-01-27 22:06
    关注

    I'd do something like this in your controller:

    $products = DB::table('products')
    ->join('product_options', 'products.id', '=', 'product_options.product_id')
    ->get();
    
    return View::make('products.show')
        ->withProducts($products);
    

    Let the Query Builder do all the hard work for you instead of writing out all of your queries, then all you have to do is loop through your $products variable in your home blade and you should be set.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器