Welcome Guest, Not a member yet? Register   Sign In
help for pagination
#1

[eluser]Unknown[/eluser]
Good afternoon everyone
Sorry for English.

I had no problems creating paging using data from a single table.
It happens that I have the following situation: I have two tables:

table1
`id` int(10) NOT NULL AUTO_INCREMENT,
`nome` varchar(40) NOT NULL,
`descricao` text NOT NULL,

table2
`id` int(10) NOT NULL AUTO_INCREMENT,
`titulo` varchar(200) NOT NULL,
`categoria` int(10) NOT NULL,
`resumo` text NOT NULL,
`descricao` text NOT NULL,
`foto` varchar(45) NOT NULL,


Here is the code to display the contents of a given table2

<?php
class Conteudo extends Controller {

function __construct()
{
parent::Controller();
$this->load->library('pagination');
}

function item($id)
{
$query = $this->db->get('table1');
$dados['table1'] = $query->result();

$my_query = "SELECT
tabel2.*,
table1.name as name_item
FROM table2
JOIN table1
ON table2.item = table1.id
WHERE table2.item =".$id; //I believe it is there that I should complete the instructions for paging ...

// I decided to make this change
$limite=2
$per_page=2

$my_query= $this->db->query ("SELECT table1.*, JOIN table1 ON table2.item = table1.id , $limite, $offset,$per_page");
// but returned the following error = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN table1 ON table2.item = table1.id , 2, 1,2' at line 1
SELECT conteudo.*, JOIN categorias ON conteudo.categoria = categorias.id , 2, 1,2


$query = $this->db->query($my_query);

$dados['table2_table1'] = $query->result(); // this result needs to be passed with instructions pagination ...

$this->load->view('script2',$dados);

}


Here is the code script2


<?php


foreach ($table2_table1 as $item):
echo img("img/".$item->foto);
echo "<p>" .$item->resumo . "</p>";
echo "<a >id ."'>more...</a>";
echo "</span>";
endforeach;
echo "</div>";


?&gt;


can someone give me a suggestion

Thanks
#2

[eluser]theprodigy[/eluser]
Code:
$sql = "SELECT
        tabel2.*,
        table1.name as name_item
        FROM table2
        JOIN table1
        ON table2.item = table1.id // I did not see table2.item in your table definition
        WHERE table2.item =”.$id // I did not see table2.item in your table definition
        LIMIT $offset,$per_page";
                                              
$my_query= $this->db->query ($sql);
I copied the above query from your first sql code and modified it with the LIMIT clause.

I believe the above should work for you, but I have a couple of questions:

Why are you doing this query in the controller, and not in the model?
And why are you hand writing your query, and not using CodeIgniter's Active Record?

Also, when posting code, please remember to surround your code with the code blocks. It makes it easier to read.




Theme © iAndrew 2016 - Forum software by © MyBB