Dynamic mysql php menu ( by using CodeIgniter )
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
class Site_model extends Model {
function Site_model()
{
parent::Model();
}
function page_config()
{
$page;
$page = array();
$page['title'] = 'Sites';
return $page;
}
function pages()
{
$id = $this->uri->segment(3);
$this->db->where('id', $id);
$sql = $this->db->get('pages');
return $sql;
}
function navigation()
{
# Get menu
$this->db->order_by('order', 'asc');
$this->db->where('subid', '0');
$result = $this->db->get('navigation');
$number = $result->num_rows();
$i = 0;
WHILE ($i < $number)
{
$id = $result->result($result,$i,'id');
$link = $result->result($result,$i,'link');
$title = $result->result($result,$i,'title');
$render =
'<h3><a name="'.$link.'">'.$title.'</a></h3>'.
'<div>'.
'<ul>';
# Get submenu
$this->db->order_by('order', 'asc');
$this->db->where('subid', $result->result($result,$i,'id'));
$result2 = $this->db->get('navigation');
$number2 = $result2->num_rows();
$k = 0;
WHILE ($k < $number2)
{
$id = $result->result($result,$k,'id');
$link = $result->result($result,$k,'link');
$title = $result->result($result,$k,'title');
$render =
'<li><a name="'.$link.'">'.$title.'</a></li>';
$k++;
}
$render =
'</ul>'.
'</div>';
$i++;
}
while(@mysql_close()) { }
}
}
/* End of file site_model.php */
/* Location: ./system/application/controllers/site_model.php */
[/code]
class Site_model extends Model {
function Site_model()
{
parent::Model();
}
function page_config()
{
$page;
$page = array();
$page['title'] = 'Sites';
return $page;
}
function pages()
{
$id = $this->uri->segment(3);
$this->db->where('id', $id);
$sql = $this->db->get('pages');
return $sql;
}
function navigation()
{
# Get menu
$this->db->order_by('order', 'asc');
$this->db->where('subid', '0');
$result = $this->db->get('navigation');
$number = $result->num_rows();
$i = 0;
WHILE ($i < $number)
{
$id = $result->result($result,$i,'id');
$link = $result->result($result,$i,'link');
$title = $result->result($result,$i,'title');
$render =
'<h3><a name="'.$link.'">'.$title.'</a></h3>'.
'<div>'.
'<ul>';
# Get submenu
$this->db->order_by('order', 'asc');
$this->db->where('subid', $result->result($result,$i,'id'));
$result2 = $this->db->get('navigation');
$number2 = $result2->num_rows();
$k = 0;
WHILE ($k < $number2)
{
$id = $result->result($result,$k,'id');
$link = $result->result($result,$k,'link');
$title = $result->result($result,$k,'title');
$render =
'<li><a name="'.$link.'">'.$title.'</a></li>';
$k++;
}
$render =
'</ul>'.
'</div>';
$i++;
}
while(@mysql_close()) { }
}
}
/* End of file site_model.php */
/* Location: ./system/application/controllers/site_model.php */
[/code]
Code (php)
probeer eens:
en CodeIgniter is een MVC Principe
en wat ik aan code poste is de Model
Gewijzigd op 15/07/2010 12:23:36 door jaap Jolman
mss kan je ook even posten of je errors oid krijgt want hij doet het niet kunnen we niet zoveel mee..
ik krijg geen error maar ik krijg niks te zien
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class Site extends Controller {
function Site()
{
parent::Controller();
$this->load->model('site_model');
}
function index()
{
redirect(site_url('site/gui/'));
}
function gui()
{
$nav = $this->site_model->navigation();
$page = $this->site_model->page_config();
$this->load->view('site/site',array('page' => $page, 'nav'=> $nav));
}
function pages()
{
$sql = $this->site_model->pages();
$this->load->view('site/pages',array('sql' => $sql));
}
}
/* End of file site.php */
/* Location: ./system/application/controllers/site.php */
?>
class Site extends Controller {
function Site()
{
parent::Controller();
$this->load->model('site_model');
}
function index()
{
redirect(site_url('site/gui/'));
}
function gui()
{
$nav = $this->site_model->navigation();
$page = $this->site_model->page_config();
$this->load->view('site/site',array('page' => $page, 'nav'=> $nav));
}
function pages()
{
$sql = $this->site_model->pages();
$this->load->view('site/pages',array('sql' => $sql));
}
}
/* End of file site.php */
/* Location: ./system/application/controllers/site.php */
?>
Model:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
class Site_model extends Model {
function Site_model()
{
parent::Model();
}
function page_config()
{
$page;
$page = array();
$page['title'] = 'Sites';
return $page;
}
function pages()
{
$id = $this->uri->segment(3);
$this->db->where('id', $id);
$sql = $this->db->get('pages');
return $sql;
}
function navigation()
{
# Get menu
# phpddm_menu(TITLE, VTITLE, WIDTH, URL, TARGET)
$this->db->order_by('order', 'asc');
$this->db->where('subid', '0');
$result = $this->db->get('navigation');
$number = $result->num_rows();
$i = 0;
WHILE ($i < $number)
{
$id = $result->result($result,$i,'id');
$link = $result->result($result,$i,'link');
$title = $result->result($result,$i,'title');
$render =
'<h3><a name="'.$link.'">'.$title.'</a></h3>'.
'<div>'.
'<ul>';
# Get submenu
# phpddm_submenu(TITLE, URL, TARGET)
$this->db->order_by('order', 'asc');
$this->db->where('subid', $result->result($result,$i,'id'));
$result2 = $this->db->get('navigation');
$number2 = $result2->num_rows();
$k = 0;
WHILE ($k < $number2)
{
$id = $result->result($result,$k,'id');
$link = $result->result($result,$k,'link');
$title = $result->result($result,$k,'title');
$render =
'<li><a name="'.$link.'">'.$title.'</a></li>';
$k++;
}
$render =
'</ul>'.
'</div>';
$i++;
}
while(@mysql_close()) { }
}
}
/* End of file site_model.php */
/* Location: ./system/application/controllers/site_model.php */
?>
class Site_model extends Model {
function Site_model()
{
parent::Model();
}
function page_config()
{
$page;
$page = array();
$page['title'] = 'Sites';
return $page;
}
function pages()
{
$id = $this->uri->segment(3);
$this->db->where('id', $id);
$sql = $this->db->get('pages');
return $sql;
}
function navigation()
{
# Get menu
# phpddm_menu(TITLE, VTITLE, WIDTH, URL, TARGET)
$this->db->order_by('order', 'asc');
$this->db->where('subid', '0');
$result = $this->db->get('navigation');
$number = $result->num_rows();
$i = 0;
WHILE ($i < $number)
{
$id = $result->result($result,$i,'id');
$link = $result->result($result,$i,'link');
$title = $result->result($result,$i,'title');
$render =
'<h3><a name="'.$link.'">'.$title.'</a></h3>'.
'<div>'.
'<ul>';
# Get submenu
# phpddm_submenu(TITLE, URL, TARGET)
$this->db->order_by('order', 'asc');
$this->db->where('subid', $result->result($result,$i,'id'));
$result2 = $this->db->get('navigation');
$number2 = $result2->num_rows();
$k = 0;
WHILE ($k < $number2)
{
$id = $result->result($result,$k,'id');
$link = $result->result($result,$k,'link');
$title = $result->result($result,$k,'title');
$render =
'<li><a name="'.$link.'">'.$title.'</a></li>';
$k++;
}
$render =
'</ul>'.
'</div>';
$i++;
}
while(@mysql_close()) { }
}
}
/* End of file site_model.php */
/* Location: ./system/application/controllers/site_model.php */
?>
View:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
// Starting Header
$render =
'<html>'.
'<head>'.
'<title>'.$page['title'].'</title>'.
'<link rel="stylesheet" type="text/css" href="'.site_url('/public/css/vader/jquery-ui-1.8.2.custom.css').'"/>'.
'<link rel="stylesheet" type="text/css" href="'.site_url('public/css/sites.css').'"/>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/jquery-1.4.2.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/jquery-1.4.2.min.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/jquery.form.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/ui/jquery-ui-1.8.2.custom.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/ui/jquery-ui-i18n.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/ui/jquery-ui-1.8.2.custom.min.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/controllers/sites/algemeen.js').'"></script>'.
'</head>'.
'<body>';
echo $render;
// starting Content
$render =
'<div id="container">'.
'<div id="header">'.
'<div id="intern">'.
'Rij Met Koos'.
'</div>'.
'</div>'.
'<div id="body">'.
'<div id="navigation">'.
'<div id="intern">'.
$nav.
'</div>'.
'</div>'.
'<div id="content">'.
'<div id="intern">'.
'</div>'.
'</div>'.
'<div class="divider"></div>'.
'</div>'.
'<div id="footer">'.
'<div id="intern">'.
'footer'.
'</div>'.
'</div>'.
'</div>';
echo $render;
// Starting footer
$render =
'</body>'.
'</html>';
echo $render;
?>
// Starting Header
$render =
'<html>'.
'<head>'.
'<title>'.$page['title'].'</title>'.
'<link rel="stylesheet" type="text/css" href="'.site_url('/public/css/vader/jquery-ui-1.8.2.custom.css').'"/>'.
'<link rel="stylesheet" type="text/css" href="'.site_url('public/css/sites.css').'"/>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/jquery-1.4.2.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/jquery-1.4.2.min.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/jquery.form.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/ui/jquery-ui-1.8.2.custom.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/ui/jquery-ui-i18n.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/jquery/ui/jquery-ui-1.8.2.custom.min.js').'"></script>'.
'<script type="text/javascript" src="'.site_url('public/scripts/controllers/sites/algemeen.js').'"></script>'.
'</head>'.
'<body>';
echo $render;
// starting Content
$render =
'<div id="container">'.
'<div id="header">'.
'<div id="intern">'.
'Rij Met Koos'.
'</div>'.
'</div>'.
'<div id="body">'.
'<div id="navigation">'.
'<div id="intern">'.
$nav.
'</div>'.
'</div>'.
'<div id="content">'.
'<div id="intern">'.
'</div>'.
'</div>'.
'<div class="divider"></div>'.
'</div>'.
'<div id="footer">'.
'<div id="intern">'.
'footer'.
'</div>'.
'</div>'.
'</div>';
echo $render;
// Starting footer
$render =
'</body>'.
'</html>';
echo $render;
?>
Gewijzigd op 15/07/2010 12:37:20 door jaap Jolman
A Database Error Occurred
Error Number: 1054
Unknown column 'Array' in 'where clause'
SELECT * FROM (`rijmetkoos_navigation`) WHERE `subid` = Array ORDER BY `order` asc
*Mental note: Stay away from code igniter*
Ik vind dit dus echt niet goed geschreven, probeer eens alles wat stricter te zetten, geef de functies een ppp, en zet error reporting aan.
als je de config niet op strict zet laat hij dit toe en inplaats van nutteloos commentaar te leveren zou je ook wat nuttige tips kunnen geven
Jaap Jolman op 15/07/2010 12:45:55:
als je de config niet op strict zet laat hij dit toe en inplaats van nutteloos commentaar te leveren zou je ook wat nuttige tips kunnen geven
Ik gaf geen nutteloos commentaar, ik gaf je een tip. Zet error reporting aan. Een beter tip is stop met code igniter te gebruiken mja... das flauw he. dus zet error reporting aan, kijk wat het zegt.
dat error reporting staat aan maar hij doet gewoon helemaal niks
En bij bron weergeven staat ook niks? doe dan eens in je terminal "tail /var/log/apache2/error.log"
zodat de parent de
<h3><a>Parent</a></h3>
<div>
<ul>
en dat de submenus zo werden herhaalt
<li><a>subitem1</a></li>
<li><a>subitem2</a></li>
</ul>
<div>
de error log is leeg
Code (php)
1
2
3
2
3
php_flag log_errors On
php_value error_log /var/www/logs/php_errors
php_value error_reporting 30719
php_value error_log /var/www/logs/php_errors
php_value error_reporting 30719
Of waar je de php error log ook wilt hebben.
Jaap Jolman op 15/07/2010 12:56:32:
de error log is leeg
Dan zijn er geen errors, en returned het gewoon niks. ik zou met echo's proberen te achterhalen tot waar je code werkt, en waarom het niks returned. gebruik je hersenen, debug :)
Controller:
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?php
function gui()
{
$nav = $this->site_model->navigation();
$page = $this->site_model->page_config();
$this->load->view('site/site',array('page' => $page, 'nav'=> $nav));
}
?>
function gui()
{
$nav = $this->site_model->navigation();
$page = $this->site_model->page_config();
$this->load->view('site/site',array('page' => $page, 'nav'=> $nav));
}
?>
Model:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
function navigation()
{
// Parent Menu
$this->db->order_by('order', 'asc');
$this->db->where('subid', '0');
$query = $this->db->get('navigation');
$i = 0;
foreach($query->result() as $row)
{
$parentitem[$i]['id'] = $row->id;
$parentitem[$i]['link'] = $row->link;
$parentitem[$i]['title'] = $row->title;
// Sub Menu
$this->db->order_by('order', 'asc');
$this->db->where('subid', $parentitem[$i]['id']);
$subquery = $this->db->get('navigation');
$sub = 0;
foreach($subquery->result() as $row)
{
$subitem[$sub]['id'] = $row->id;
$subitem[$sub]['link'] = $row->link;
$subitem[$sub]['title'] = $row->title;
$sub++;
}
$i++;
}
$nav;
$nav = array();
$nav['parent'] = $parentitem;
$nav['sub'] = $subitem;
return $nav;
}
?>
function navigation()
{
// Parent Menu
$this->db->order_by('order', 'asc');
$this->db->where('subid', '0');
$query = $this->db->get('navigation');
$i = 0;
foreach($query->result() as $row)
{
$parentitem[$i]['id'] = $row->id;
$parentitem[$i]['link'] = $row->link;
$parentitem[$i]['title'] = $row->title;
// Sub Menu
$this->db->order_by('order', 'asc');
$this->db->where('subid', $parentitem[$i]['id']);
$subquery = $this->db->get('navigation');
$sub = 0;
foreach($subquery->result() as $row)
{
$subitem[$sub]['id'] = $row->id;
$subitem[$sub]['link'] = $row->link;
$subitem[$sub]['title'] = $row->title;
$sub++;
}
$i++;
}
$nav;
$nav = array();
$nav['parent'] = $parentitem;
$nav['sub'] = $subitem;
return $nav;
}
?>
View:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Ik heb alleen de code die er toe doet gepost om verwarring te verkomen
de Parents komen nu wel goed terecht alleen de sub menus bijven hangen dus krijg onder iedere parent de zelfde sub en dat is de sub die als laatste wordt opgehaalt uit de db
Gewijzigd op 15/07/2010 15:25:06 door jaap Jolman
reageert er aub iemand
Graag niet bumpen; twee berichten van jezelf na elkaar binnen 24 uur plaatsen. Heb je een toevoeging aan je vorige bericht, gebruik dan het 'wijzigen' icoontje.[/modedit]
Gewijzigd op 15/07/2010 18:14:53 door Joren de Wit