[eluser]Ramania[/eluser]
hello people,
i'm thankful again for this great framework and this great community of professionals, and as much as i love finding out how things work by my own as much as it makes me bothered to write a question, but since the idea of any community is to help, i'd be thankful if someone asked the following two questions:
1. i am trying to make it possible to sort data either by different factors, but the result in the listing page keeps giving me the same order, even though the query is correct and it works!, here's the code below:
Code:
function Index(){
#get sorting method 0=name, 1=country, 3=populartiy.
if ($this->uri->segment(3) == null){
$content['sortby'] = "0";
$sort_by_case = "0";
} else {
$content ['sortby'] = $this->uri->segment(3);
$sort_by_case = $this->uri->segment(3);
}
#do the query based on the sorting method.
switch($sort_by_case){
case 0:
$sort_by_query = ('SELECT artist_id, artist_name, artist_country FROM artists Order by artist_name');
case 1:
$sort_by_query = ('SELECT artist_id, artist_name, artist_country FROM artists order by artist_country');
case 2:
$sort_by_query = ('SELECT artist_id, artist_name, artist_country FROM artists order by view_count');
}
$content['query'] = $this->db->query($sort_by_query);
$content['viewname'] = "list_artists";
$this->load->view('mainview',$content);
}
and here is the code for the view page
Code:
<?
$sorting_options = array ('By name','By country','By populartiy');
$js_onchange = 'onChange = "get_item();"';
echo "<form name=\"rami\">";
echo "Sorting options:".form_dropdown('artists',$sorting_options,$sortby,$js_onchange);
echo "</form>";
?>
<ul>
<?php foreach ($query->result() as $item): ?>
<li>
<?php
echo anchor('list_artists/artistpage/'.$item->artist_id ,$item->artist_name."- ".$item->artist_country);
?>
</li>
<?php endforeach; ?>
</ul>
now i know i am not a professional coder, but since this's my first application so far, i am trying my best to write the "best" code.
the second question is: am i doing extra work in my code? or it's ok? i don't like shortcuts, but since it's web, and bandwidth is involved then the lesser the code the best the results! or that's what i guess!
thank you folks, i appreciate your time.
ps: the uri third segment is routed correctly and i tested it many times, as i tried an echo to make sure everything work, and it's passed through a javascript as the following..
Code:
function get_item()
{
[removed] = "http://localhost/mmdportal/index.php/list_artists/sortby/"+document.rami.artists.value;
}
the removed code refers to the document location.