0
I turned that code 1 into code 2
1)//$palpites=DB::select("SELECT * FROM palpite WHERE id_u='$id' order by id_c desc ");
2) $palpites = DB::table('palpite')->where('id_u',$id)->orderby('id_c','desc') ->paginate(3);
How to turn this code below into the same 1.2 example?
$confrontos=DB::select("SELECT * FROM confrontos as c, palpite as p WHERE p.id_u ='$id' AND EXISTS (SELECT * FROM palpite WHERE c.id = p.id_c) order by id_c desc ");
Can you complete it? I’m a little insecure about this code.
– Dan Even
I can try yes. But I gave an example only of the part that involves the sub-query. The previous query you can base on the example you used in item (2). What is the main idea of the query? You want to return exactly what?
– Lorenzo Fernandez
The two codes refer to the same thing(1,2)... code is correct, but the intention to transform it is to paginate! but this other code is more complex... and I’m not able to transform!
– Dan Even
Got it. So, let’s go. The query that involves a sub-query is not necessary to do the paging. It doesn’t seem right. In Laravel you can simply page like this: $table = DB::table('table')->paginate(10); and in your view just render like this: $table->render();
– Lorenzo Fernandez
Lorenzo, how would you look?
– Dan Even
@Daneven you need only use the "paginate()" of Eloquent. I still don’t understand if it’s the query with the sub-query that you want to paginate or the one that you wrote in item (2). It’s confusing.
– Lorenzo Fernandez
then! I have example 1) which I turned into 2) to be able to paginate, and it works! I want to do the same thing with the example below, to paginate! only that the code is more complex, uses two tables reference, but I would like to do the same thing.
– Dan Even
Let’s go continue this discussion in chat.
– Lorenzo Fernandez