php - 用于连接的查询生成器新索引

标签 php mysql laravel

我有一个查询生成器:

$Metro = DB::table('fijacion')->where('tipo','Metro')->join('adp', 'fijacion.id', '=', "adp.id_fijacion")->get();

它返回一些 id 不是顺序的记录,即 1 5 6 14 等

$Metro not sequential

如果该查询具有顺序值 0 1 2 3 4 等,我将该查询与另一个查询相关联。

$Metro[] is a sequential

foreach($Metrop as $Metro){
    $array = explode("|", $Metro->nr);
    $Metro = DB::table('fijacion')->where('tipo','Metro')->join('adp', 'fijacion.id', '=', "adp.id_fijacion")->get();
    $MetroA[] = DB::table('users')
              ->select('*')
              ->whereIn('numero',$array)
              ->where('categoria', '<=', 3)
              ->join('puntos', 'users.numero', '=', "puntos.nr")
              ->orderby('categoria', 'asc')
              ->orderby('total', 'asc')
              ->get();
 }

我需要的是能够按顺序将 $ Meter 与我的其他句子连接起来。

@foreach($MetroA[($Metro->xxx)] as $item)

@endforeach

$Metro->xxx is a sequential

那是不应该做的

这可能吗??

谢谢。

最佳答案

如果你使用这个会更容易:

@foreach($Metro as $i => $Metro)
    .....
@endforeach

这无需任何额外代码即可完成工作。

关于php - 用于连接的查询生成器新索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45601768/

相关文章:

php - 为什么访问 Laravel 应用程序时出现 "no such file or directory ... autoload.php"?

php - 如何从 Redis 获取 session 列表?

php - 列出目录内容(php)

php - 由于列不是直接连接的,如何用名称替换 ID 号? (PHP/MySQL)

python - scrapy exceptions.TypeError : 'int' object has no attribute '__getitem__'

php while循环中数组的最大值

php - 如何在mysql的数据库中存储图像和文本

MySQL - 获取前一行数据时查询速度慢

javascript - Laravel 无法上传图片

jquery - laravel 4:URL::route 与 jquery