[eluser]bobbit6k[/eluser]
Hi
!
I have a logical problem withj my first CI app.
As you see in the image i have a list of items (web pages).
This view takes all the items from the "pages" table and order the query by the pageorder
field.
Now:
0) Disclaimer: prolly i will make you laugh, expert dudes
. I'm not a very good programmer and probably i'll sound a little stupid too.
.
1) (SEE ATTACCHED FILE)
(In my mind) the arrow imgs should contain a link
to a controller taking two numerical parameters (id of the page and id of the previous/next item).
ipotetically this controller would swap the pageorder field between the parameters (idPages) that i just passed.
Example:
* arrow up ->
Code:
<a href="mysite/path/to/order_up/this_page_id/previous_page_id/">
<img src="mysite/path/to/arrowup.png"/>
</a>
* arrow down ->
Code:
<a href="mysite/path/to/order_down/this_page_id/next_page_id/">
<img src="mysite/path/to/arrowup.png"/>
</a>
2)
Just to make things well, on the first/last page i should not have the Order_up/order_down code.
3)
what did i do?
my view ->
Code:
<?php foreach ($results->result() as $row): ?> // results get the datas from the "pages" table
<?php
$previous_row = $this->mpages->select_page_previous($row->idPages); // see below, i wrote the model function.
$next_row = $this->mpages->select_page_next($row->idPages);
$empty_char = "";
?>
.....
<?php
if ($previous_row)
{
echo <<<qwerty
<li class="inline"><a >idPages/$previous_row->idPages/">
<img src="$path/static/img/up1.png">pagetitle: Sposta in alto" width="25" height="25"/>
</a> </li>
qwerty;
}
else {echo $empty_char;}
if ($next_row)
{
echo <<<qwerty
<li class="inline"> <a >idPages/$next_row">
<img src="$path/static/img/down1.png">pagetitle?>: Sposta in basso" width="25" height="25"/>
</a></li>
qwerty;
}
else {echo $empty_char;} ?>
.....
//
//
Here starts the mpages model select_page_previous($row->idPages);
//
Code:
function select_page_previous($prova)
{
$this->db->order_by("pageorder", "asc");
$query = $this->db->get('pages');
$num_rows=$query->num_rows();
foreach ($query->result() as $row)
{
if ($prova==$row->idPages) {$exit = $query->previous_row();}
}
return $exit;
}
//
/
/Here finishes the model (the other one works the same way)
//
4)
What did i get?
nothing but troubles
1) all the urls have as second parameter the firstpageid and the if statement makes me print the double arrows on the top/bottom elements.
5)
Waht i'md oing wrong? I'm
Not asking for the working code just few ideas/critics
Now i also have the idea that isn't a good code even if it could work, i've nested multiple queries and should be very slow.
I also feel like i'm improperly using $query->previous_row() $query->next_row() or the wrong statements/conditions.
6)
Cheers