Coderrrr
Coderrrr

Reputation: 230

Dynamic navigation with php

Hi I am building a site directory and I'm having a little trouble understanding how to use the $_GET['page'] function

I understand you can use this to navigate across sites which are dynamically made, in fact I have a site which uses it currently but I did not create that set of code and don't understand the logic behind it..

I know how I will handle the navigation - the homepage will contain sites with a link to both their website and to a listing on my site. The listing url will contain the category and the ID of the site.

I want it to look like domain/category/siteid or like domain/index.php?cat=2&id=58

I understand I will probably need to use htaccess to change the url to look like the first example..

So anyway, the url will contain both the site ID and category which I want to then use to associate with the dynamically loaded page, with the relevant category and site listing.

This seems to be the standard way of loading pages in PHP but I've been unable to find a good guide on how to do it, I will also need to read the data from the url to make a database call so if anyone could explain how I can read the url to get the listing id and category it would be greatly appreciated!

Thanks a lot

Luke

Upvotes: 0

Views: 269

Answers (2)

ferdynator
ferdynator

Reputation: 6410

You answered your question more or less yourself. The parameters from the URL are available in PHP in the $_GET array. For your example the category would be $_GET['cat'] (would return 2) and the ID would be $_GET['id'] (would return 58).

Take care of SQL-Injections. Also see other global variables

Upvotes: 2

Mohammed Saqib Rajput
Mohammed Saqib Rajput

Reputation: 1370

                <ul>
                    <li><a href="index.php">HOME</a></li>
                    <?
                    $first_query = "SELECT * FROM navigation_menu WHERE `status` ='active'";
                    $first_menu = $db->select($first_query);
                    for($a = 0 ; $a < count($first_menu) ; $a++)
                    {?>
                        <li><a href="general.php?id=<?=$first_menu[$a]['id']?>&general=m"> <?=$first_menu[$a]['navigation']?> </a>

                                <?$second_query = "SELECT * FROM sub_menu WHERE nav_menu_id=".$first_menu[$a]['id']." AND `status` ='active'";
                                $second_menu = $db->select($second_query);

                                if(count($second_menu) > 0)
                                {?>
                                    <ul>
                                    <?for($b = 0 ; $b < count($second_menu) ; $b++)
                                    {
                                        if($second_menu[$b]['sub_nav_menu'] != '')
                                        {?>
                                            <li> <a href="general.php?id=<?=$first_menu[$a]['id']?>&sid=<?=$second_menu[$b]['id']?>&general=s"><?=$second_menu[$b]['sub_nav_menu']?></a>

                                                <?$third_query = "SELECT * FROM sub_child_menu WHERE nav_menu_id=".$first_menu[$a]['id']." AND sub_nav_id=".$second_menu[$b]['id']." AND `status` ='active'";
                                                $third_menu = $db->select($third_query);

                                                if(count($third_menu) > 0)
                                                {?>
                                                    <ul>
                                                        <?
                                                        for($c = 0 ; $c < count($third_menu) ; $c++)
                                                        {?>
                                                            <li>
                                                                <a href="general.php?id=<?=$first_menu[$a]['id']?>&sid=<?=$second_menu[$b]['id']?>&cid=<?=$third_menu[$c]['id']?>&general=c">
                                                                    <?=$third_menu[$c]['child_menu']?>
                                                                </a>
                                                            </li>
                                                        <?}?>
                                                    </ul>
                                                <?}?>
                                            </li>
                                        <?}
                                    }?>
                                </ul>
                            <?}?>
                        </li>
                    <?}?>
                </ul>

Upvotes: -1

Related Questions