Laravel 5.2 Query Builder作为单个数组(不是2D或3D)

时间:2016-03-08 05:39:05

标签: php sql arrays laravel laravel-5.2

这是我的查询。

public void dataGrid(ArrayList<String> pv)
{

    TableLayout stk = (TableLayout) findViewById(R.id.ShowTable);
    for (int i = 0; i <= pv.size()-1;)
     {
         TableRow tbrow = new TableRow(this);




         TextView t1v = new TextView(this);
         t1v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
         t1v.getLayoutParams().width = 0;
         t1v.setBackgroundResource(R.drawable.cellshape);
         t1v.setText("" + pv.get(i));

         t1v.setTextColor(Color.WHITE);
         t1v.setGravity(Gravity.CENTER);
         tbrow.addView(t1v);


         TextView t2v = new TextView(this);
         t2v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
         t2v.getLayoutParams().width = 0;
         t2v.setBackgroundResource(R.drawable.cellshape);
         t2v.setText("" + pv.get(i+1));

         t2v.setTextColor(Color.WHITE);
         t2v.setGravity(Gravity.CENTER);
         tbrow.addView(t2v);

         TextView t3v = new TextView(this);
         t3v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
         t3v.getLayoutParams().width = 0;
         t3v.setBackgroundResource(R.drawable.cellshape);
         t3v.setText("" + pv.get(i+2));

         t3v.setTextColor(Color.WHITE);
         t3v.setGravity(Gravity.CENTER);
         tbrow.addView(t3v);

         TextView t4v = new TextView(this);
         t4v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
         t4v.getLayoutParams().width = 0;
         t4v.setBackgroundResource(R.drawable.cellshape);
         t4v.setText("" + pv.get(i+3));

         t4v.setTextColor(Color.WHITE);
         t4v.setGravity(Gravity.CENTER);
         tbrow.addView(t4v);



         lastValue=i+3;
         i=lastValue+1;
         stk.addView(tbrow);



 }
}

输出总是原始的。喜欢以下图片

enter image description here

如果我想访问 zakathorg_id 。我必须使用foreach循环。我无法访问

$mem = DB::table('user_zakathorg') ->JOIN('zakathorgs', 'user_zakathorg.zakathorg_id', '=', 'zakathorgs.ID') ->WHERE('user_id', '=', Auth::user()->id ) ->SELECT('zakathorg_id', 'orgName')->get();

我怎样才能将其简单地用作$mem[0]['zakathorg_id]

1 个答案:

答案 0 :(得分:1)

使用first()方法代替get()

$mem = DB::table('user_zakathorg')
       ->JOIN('zakathorgs', 'user_zakathorg.zakathorg_id', '=', 'zakathorgs.ID')
       ->WHERE('user_id', '=', Auth::user()->id )
       ->SELECT('zakathorg_id', 'orgName')->get();
// You can access $mem->zakathorg_id now