Buying Need help with php function - simple change

Discussion in 'Programming' started by Neutron, Jan 29, 2010.

  1. #1
    I have a function which outputs the navigation panel in a quiz module for one of my sites. Problem is I need to change the layout of the nav panel. The code is below. You can see that links to pages are output in the nav panel. However, when there's a lot of pages, they stretch all the way off the right side of the screen and the user has to scroll to the right to see them all. It looks unprofessional.

    I need to have a fix where the pages, if more than say 20, are output (wrapped) on multiple rows in the nav panel.

    Who can help for $10? Payment by Paypal when work is finished.

    function quiz_print_navigation_panel($page, $pages) {
        //$page++;
        echo '<div class="paging pagingbar">';
        echo '<span class="title">' . get_string('page') . ':</span>&nbsp;';
        if ($page > 0) {
            // Print previous link
            $strprev = get_string('previous');
            echo '&nbsp;<a class="previous" href="javascript:navigate(' . ($page - 1) . ');" title="'
             . $strprev . '">(' . $strprev . ')</a>&nbsp;';
        }
        for ($i = 0; $i < $pages; $i++) {
            if ($i == $page) {
                echo '&nbsp;<span class="thispage">'.($i+1).'</span>&nbsp;';
            } else {
                echo '&nbsp;<a href="javascript:navigate(' . ($i) . ');">'.($i+1).'</a>&nbsp;';
            }
        }
    
        if ($page < $pages - 1) {
            // Print next link
            $strnext = get_string('next');
            echo '&nbsp;<a class="next" href="javascript:navigate(' . ($page + 1) . ');" title="'
             . $strnext . '">(' . $strnext . ')</a>&nbsp;';
        }
        echo '</div>';
    }
    
    Code (markup):
     
    Neutron, Jan 29, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Try:

    function quiz_print_navigation_panel($page, $pages) {
        //$page++;
        
        if($pages < 20){
        echo '<div class="paging pagingbar">';
        echo '<span class="title">' . get_string('page') . ':</span>&nbsp;';
        if ($page > 0) {
            // Print previous link
            $strprev = get_string('previous');
            echo '&nbsp;<a class="previous" href="javascript:navigate(' . ($page - 1) . ');" title="'
             . $strprev . '">(' . $strprev . ')</a>&nbsp;';
        }
        for ($i = 0; $i < $pages; $i++) {
            if ($i == $page) {
                echo '&nbsp;<span class="thispage">'.($i+1).'</span>&nbsp;';
            } else {
                echo '&nbsp;<a href="javascript:navigate(' . ($i) . ');">'.($i+1).'</a>&nbsp;';
            }
        }
    
        if ($page < $pages - 1) {
            // Print next link
            $strnext = get_string('next');
            echo '&nbsp;<a class="next" href="javascript:navigate(' . ($page + 1) . ');" title="'
             . $strnext . '">(' . $strnext . ')</a>&nbsp;';
        }
        echo '</div>';
        } else {
        
            echo '<div class="paging pagingbar">';
        echo '<span class="title">' . get_string('page') . ':</span>&nbsp;';
        if ($page > 0) {
            // Print previous link
            $strprev = get_string('previous');
            echo '&nbsp;<a class="previous" href="javascript:navigate(' . ($page - 1) . ');" title="'
             . $strprev . '">(' . $strprev . ')</a>&nbsp;<br>';
        }
        for ($i = 0; $i < $pages; $i++) {
            if ($i == $page) {
                echo '&nbsp;<span class="thispage">'.($i+1).'</span>&nbsp;';
            } else {
                echo '&nbsp;<a href="javascript:navigate(' . ($i) . ');">'.($i+1).'</a>&nbsp;<br>';
            }
        }
    
        if ($page < $pages - 1) {
            // Print next link
            $strnext = get_string('next');
            echo '&nbsp;<a class="next" href="javascript:navigate(' . ($page + 1) . ');" title="'
             . $strnext . '">(' . $strnext . ')</a>&nbsp;<br>';
        }
        echo '</div>';
        }
    }
    PHP:
    Also would help if you could let me know your site url so i can see...
     
    danx10, Jan 29, 2010 IP
  3. Neutron

    Neutron Well-Known Member

    Messages:
    701
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    job is done. thanks everyone.
     
    Neutron, Jan 29, 2010 IP
  4. Neutron

    Neutron Well-Known Member

    Messages:
    701
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    danx10, I went with an earlier fix from another person.
     
    Neutron, Jan 29, 2010 IP