Welcome Guest, Not a member yet? Register   Sign In
little issue with url redirect
#1

[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
------------------------------------------------------------------------------------
#2

[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
#3

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

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

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

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

Happy Coding,
DesignFellow
#7

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




Theme © iAndrew 2016 - Forum software by © MyBB