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

Mysql $db->query() error on echo

Discussion in 'XenForo Development Discussions' started by Lu Jia, May 24, 2011.

  1. Lu Jia

    Lu Jia Active Member

    Hi,
    today I got a problem to output the result of a query:
    PHP:
    $group_founder 1;
    $group_founder_username $db->query("SELECT username FROM `xf_user` WHERE user_id = '$group_founder';");
    echo 
    $group_founder_username;
    When i save this file i'll have this error:
    Code:
    Server Error
    
    Object of class Zend_Db_Statement_Mysqli could not be converted to string
    
    XenForo_Application::handlePhpError() in ExternalPages/ControllerPublic/Group/Index.php at line 101
    ExternalPages_ControllerPublic_Group_Index->actionIndex() in XenForo/FrontController.php at line 310
    XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
    XenForo_FrontController->run() in /abosulutepath/index.php at line 17
    I'm using ExternalPages addon :)

    I removed the echo and put the variable in the template:

    PHP:
    $viewParams = array(
        
    'group_founder' => $group_founder_username,
    );
    I'll have this error on the top of the page:

    HTML:
    Template Errors: EP_Group_Index
    htmlspecialchars() expects parameter 1 to be string, object given in /absolutepath/library/XenForo/Template/Abstract.php(262) : eval()'d code, line 316:
    315:            <dt>Founder del gruppo:</dt>
    316:            <dd>' . htmlspecialchars($group_founder) . '</dd>
    317:    </dl>
    Any suggestions to fix it?

    Abstract.php file:

    PHP:
            if ($this->_usingTemplateFiles())
            {
                include(
    $__template);
            }
            else
            {
                eval(
    $__template);
            }

            return 
    $__output;
        }
    line 262 : eval($__template);
     
  2. James

    James Well-Known Member

    Try changing
    Code:
    $group_founder = 1;
    to
    Code:
    $group_founder = '1';
     
  3. Lu Jia

    Lu Jia Active Member

    sorry i put
    PHP:
    $group_founder 1;
    but really is
    PHP:
    $group_founder $group_data[0]['founder'];
    I guess the problem isn't here.
     
  4. ragtek

    ragtek Guest

  5. Lu Jia

    Lu Jia Active Member

    I'll try it
    Btw i fixed it changing the value in the db from user_id in username
     
  6. Kier

    Kier XenForo Developer Staff Member

    PHP:
    $group_founder 1;

    $group_founder_username $db->fetchCol('
        SELECT username
        FROM xf_user
        WHERE user_id = ?'
    ,
        
    $group_founder
    );

    echo 
    $group_founder_username;
     
    Valter, borbole, Lu Jia and 1 other person like this.

Share This Page