CodeIgniter Forums
little issue with url redirect - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: little issue with url redirect (/showthread.php?tid=21408)



little issue with url redirect - El Forum - 08-09-2009

[eluser]coding[/eluser]
i want to redirect people to home page whenever they try to access undefined page.i've written an easy code but it isn't working.

first of all code......

Note:- I'm a newbie web developer and this is my first project I'm developing.( fun project)

This is the controller
-------------------------------------------------------------------------
function celebs()
{
$currenturl = current_url();
$compare = 'http://localhost/ci/index.php/home/celebs/';
if( $compare == $currenturl )
{
redirect('/home', 'refresh');
}
else
{
$data['query'] = $this->db->query('select * from celebs where cat_id = '.$this->uri->segment(3).' order by f_name');
$data['count'] = $this->db->query('select * from clips where celeb_id = '.$this->uri->segment(3).'');
$this->load->view('celebs',$data);
}

}
---------------------------------------------------------------------------------

now error

---------------------------------------------------------------------------------

A Database Error Occurred

Error Number: 1064

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 'order by f_name' at line 1

select * from celebs where cat_id = order by f_name
------------------------------------------------------------------------------------


little issue with url redirect - El Forum - 08-09-2009

[eluser]designfellow[/eluser]
Hi,
just change the uri segment as $this->uri->segment(3,0) in your SQL query.
Post back if you face any problem.
Happy Coding,
DesignFellow


little issue with url redirect - El Forum - 08-09-2009

[eluser]coding[/eluser]
thank you designfellow it's working. thank you very much. Ci really have good community.


little issue with url redirect - El Forum - 08-09-2009

[eluser]coding[/eluser]
ok it's working but not redirecting to home page......any idea ?? and by the way i downloaded the cheatsheet.


little issue with url redirect - El Forum - 08-09-2009

[eluser]designfellow[/eluser]
Hi,
nice to hear that its working :-)


little issue with url redirect - El Forum - 08-09-2009

[eluser]designfellow[/eluser]
Hi,
remove the 'refresh' parameter from redirect.
Else, change as redirect('home/index')

Happy Coding,
DesignFellow


little issue with url redirect - El Forum - 08-09-2009

[eluser]coding[/eluser]
instead i changed uri->segment(3,1) it works not exactly what i want but works.