1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

callback MYSQL row data

Discussion in 'XenForo Development Discussions' started by Brightside, Jun 28, 2016.

  1. Brightside

    Brightside New Member

    Hello, I'm trying to recreate this using PHP Callbacks and Templates. However, I'm unclear how to echo the data within the template.
    My Callback
    Code:
    <?php
    class bright_sa_sa
    {
        public static function serverteam(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
        {
    $con=mysqli_connect("127.0.0.1","XXXXXXX","XXXXXXX","XXXXXXX");
        if (mysqli_connect_errno())
        {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        $jbstaff = mysqli_query($con,"SELECT * FROM sb_admins WHERE user LIKE '%Jail%' ORDER BY srv_group DESC");
        $ttstaff = mysqli_query($con,"SELECT * FROM sb_admins WHERE user LIKE '%TTT%' ORDER BY srv_group DESC");
        $ssstaff = mysqli_query($con,"SELECT * FROM sb_admins WHERE user LIKE '%Surf%' ORDER BY srv_group DESC");
            while($jbsrow = mysqli_fetch_array($jbstaff))
            {
                $response->params['jb'] = '<div class="steamprofile" id="' . $jbsrow['srv_group'] . '" title="' . $jbsrow['authid'] . '"></div>';
            }
            while($ttsrow = mysqli_fetch_array($ttstaff))
            {
                $response->params['ttt'] = '<div class="steamprofile" id="' . $ttsrow['srv_group'] . '" title="' . $ttsrow['authid'] . '"></div>';
            }
            while($sssrow = mysqli_fetch_array($ssstaff))
            {
                $response->params['surf'] = '<div class="steamprofile" id="' . $sssrow['srv_group'] . '" title="' . $sssrow['authid'] . '"></div>';
            }
    mysqli_close($con);
    $response->templateName = 'bright_serverteam';
        }
    }
    ?>
    
    Template
    Code:
    <script src="XXXXXXX"></script>
    <xen:require css="bright_serverteam.css" />
    <div style="width: 250px">
        <div id="global">
            <center><span style="font-weight: 900; font-size: 26px">Global Admins</span></center>
            <div class="steamprofile" id="Founder" title="STEAM_0:0:40515805"></div><!--Alvarez-->
            <div class="steamprofile" id="Founder" title="MrBrightside1"></div><!--Bright-->
            <div class="steamprofile" id="Founder" title="STEAM_0:0:29656095"></div><!--Hero-->
            <div class="steamprofile" id="Founder" title="STEAM_0:1:31551356"></div><!--K0Killer-->
            <div class="steamprofile" id="Captain" title="STEAM_0:1:44639895"></div><!--Circe-->
            <div class="steamprofile" id="Captain" title="STEAM_0:1:33846347"></div><!--Forgot-->
            <div class="steamprofile" id="Captain" title="STEAM_0:0:1241826"></div><!--Lemonz-->
            <div class="steamprofile" id="Captain" title="STEAM_0:0:51633105"></div><!--Xearta-->
        </div>
        <hr />
        <center>
        <select id="serverlist">
            <option value="jb">Jailbreak</option>
            <option value="mg">Mini Games</option>
            <option value="ttt">TTT</option>
            <option value="ss">Skill Surf</option>
            <option value="sel" selected>Select A Server</option>
        </select>
        </center>
        <br />
        <div id="jb">
            <ol>
                <xen:foreach loop="$jb" value="$jbadmins">
    
                </xen:foreach>
            </ol>
        </div> 
        <div id="ttt">
            <ol>
                <xen:foreach loop="$ttt" value="$tttadmins">
                </xen:foreach>
            </ol>
        </div> 
        <div id="surf">
            <ol>
                <xen:foreach loop="$surf" value="$surfadmins">
                </xen:foreach>
            </ol>
        </div> 
    </div>
        <script>
            $(document).ready(function() {
                $("#ttt, #jb, #surf, #minigames").css("display", "none");
            });
        </script>
    
        <script>
            $('#serverlist').change(function(){
                if($('#serverlist').val() == 'jb'){
                    $('#ttt, #surf, #minigames').slideUp(500);
                    $('#jb').delay(501).slideDown(500);
                } 
                else if($('#serverlist').val() == 'ttt'){
                    $('#jb, #surf, #minigames').slideUp(500);
                    $('#ttt').delay(501).slideDown(500);
                }
                else if($('#serverlist').val() == 'ss'){
                    $('#jb, #ttt, #minigames').slideUp(500);
                    $('#surf').delay(501).slideDown(500);
                }
                else if($('#serverlist').val() == 'mg'){
                    $('#jb, #ttt, #surf').slideUp(500);
                    $('#minigames').delay(501).slideDown(500);
                }
                else if($('#serverlist').val() == 'sel'){
                    $('#jb, #ttt, #surf, #minigames').slideUp(500);
                }
            });
        </script>
    
    CSS
    Code:
    #Founder  {
        max-width: 230px;
        border-style: solid;
        border-width: 2px;
        border-color: rgba(255,132,0,.7); }
    
    #Captain  {
        max-width: 230px;
        border-style: solid;
        border-width: 2px;
        border-color: rgba(255,215,0,.7); }
    
    #Manager  {
        max-width: 230px;
        border-style: solid;
        border-width: 2px;
        border-color: rgba(168,0,255,.7); }
    
    #Agent  {
        max-width: 230px;
        border-style: solid;
        border-width: 2px;
        border-color: rgba(0,216,255,.7); }
    
     
  2. katsulynx

    katsulynx Well-Known Member

    1. You are overriding the content of your params every time you run through your while-loops.
      PHP:
      $response->params['jb'] =
      Change the above to
      PHP:
      $response->params['jb'][] =
      Proceed likewise for the other occurences
    • When running through a loop in a XenForo Template, you have to actually do something with the content in order to display it, or you'll just create additional runtime for no benefit.
      Code:
      <xen:foreach loop="$ttt" value="$tttadmins">
      </xen:foreach>
      Change the above to
      Code:
      <xen:foreach loop="$ttt" value="$tttadmins">
                  {xen:raw $tttadmins}
      </xen:foreach>
      Proceed likewise for the other occurences
    • You probably want to change from a <div> to a <li> in order for your OL to properly list them.
    • I recommend storing just the info of each member into the array and do the HTML-Generation inside the template, e.g. change the first code snippet to
      PHP:
      $response->params['jb'][] = array('group' => $jbsrow['srv_group'], 'id' => $jbsrow['authid']);
      and the loop in the template to
      HTML:
      <xen:foreach loop="$jb" value="$jbadmin">
                  <li><div class="steamprofile" id="{$jbadmin.group}" title="{$jbadmin.id}"></div></li>
      </xen:foreach>
    PS.: I'm lazy, so there might be some typos in the code, don't just copy/paste it and expect it to work. :p
     
    Brightside likes this.
  3. Brightside

    Brightside New Member

  4. Brightside

    Brightside New Member

    Do I need to do anything special to make with a widget?
    I've tried '[Advance] HTML & Template' and linking the template however it doesn't work. when I add the callback nothing shows and I get this error "The requested page could not be found."
    When I try to do a '[Advance] PHP Callback I get this error
    Code:
    An exception occurred: Argument 1 passed to bright_sa_sa::serverteam() must be an instance of XenForo_ControllerPublic_Abstract, array given in /home/mantis/www-data/mantisclan.com/library/bright/sa/sa.php on line 4
    
    [LIST=1]
    [*]XenForo_Application::handlePhpError() in bright/sa/sa.php at line 4
    [*]bright_sa_sa::serverteam()
    [*]call_user_func() in WidgetFramework/WidgetRenderer/Callback.php at line 53
    [*]WidgetFramework_WidgetRenderer_Callback->_render() in WidgetFramework/WidgetRenderer.php at line 683
    [*]WidgetFramework_WidgetRenderer->render() in WidgetFramework/Core.php at line 462
    [*]WidgetFramework_Core->renderWidget() in WidgetFramework/Core.php at line 425
    [*]WidgetFramework_Core->renderWidgets() in WidgetFramework/Core.php at line 397
    [*]WidgetFramework_Core->_renderWidgetsFor() in WidgetFramework/Core.php at line 280
    [*]WidgetFramework_Core->renderWidgetsFor() in WidgetFramework/Listener.php at line 107
    [*]WidgetFramework_Listener::template_post_render()
    [*]call_user_func_array() in XenForo/CodeEvent.php at line 58
    [*]XenForo_CodeEvent::fire() in XenForo/Template/Abstract.php at line 195
    [*]XenForo_Template_Abstract->render() in XenForo/Template/Public.php at line 110
    [*]XenForo_Template_Public->render() in XenForo/ViewRenderer/HtmlPublic.php at line 123
    [*]XenForo_ViewRenderer_HtmlPublic->renderContainer() in XenForo/FrontController.php at line 637
    [*]XenForo_FrontController->renderView() in XenForo/FrontController.php at line 158
    [*]XenForo_FrontController->run() in /home/mantis/www-data/mantisclan.com/index.php at line 13
    [/LIST]
    
    It does work 100% if I make a page and just link the php callback
     
    Last edited: Jun 29, 2016

Share This Page