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

My Own Code

Discussion in 'XenForo Development Discussions' started by abnvet, Jul 1, 2013.

  1. abnvet

    abnvet Active Member

    I've been trying to figure out how to use my own code for querying various stuff in the DB. I keep trying to figure out how to do things and it just doesn't seem to work out. So I'm resorting to writing my own code and using it inside xenforo. So if I want to use my own queries and echo's, where could I put it?
     
  2. AndyB

    AndyB Well-Known Member

    Last edited: Jul 1, 2013
    LPH likes this.
  3. ExpertPixels.com

    ExpertPixels.com Well-Known Member

    LPH likes this.
  4. abnvet

    abnvet Active Member

    Thanks for the replies guys. I'll get some reading done!
     
  5. abnvet

    abnvet Active Member

    Well, kind of but not quite. Below shows MY PHP that I want to use and not have it show up at the top of the page outside the site. BTW, I tied in my own DB connector (which works fine) to be able to use the query below. Just need it in the site not at the top. My code is painfully simple.

    <ol>";
    $user_group = '';
    $connect = new connect();
    $result = $connect->query("SELECT * FROM xf_user_group WHERE display_style_priority != '0' ORDER BY display_style_priority ASC");
    while($row = $connect->fetchassoc($result)) {
    $user_group .= "<li class=\"secondaryContent userThing\">Title:{$row['title']}</li>";
    }
    echo "{$user_group}
    </ol>

    My full point is that if I can get my own code into the Xenforo platform I can write pretty much anything without need to learn all the things and start from scratch with the system.

    Thanks in advance!
     
  6. abnvet

    abnvet Active Member

    Anyone? I tried what AndyB said and it will need to be too simple and can't get it to show without error. We just upgraded to be able to do what AndyB said.
     
  7. EasyTarget

    EasyTarget Well-Known Member

    Where do you want to put that? In a template? Where do you need it displayed?
    You want to call a stand-alone .php file?
     
  8. abnvet

    abnvet Active Member

    Yes, I do want to call a stand-alone file and have it show up in a "page". Or any other way I can show it. By using the info that AndyB talked about I can't use my PHP. I can only return something (IE - return $output;). This would mean that I can only return simple results not results that have multiple loops in them.
     
  9. AndyB

    AndyB Well-Known Member

    Once you call your php file, you can do anything you want in php, for example query the database, run 'for' loops etc.. Your results can then be displayed in the template.
     
  10. EasyTarget

    EasyTarget Well-Known Member

    Well you can create a node, that's a page.
    Then in page node properties, make the call back, to your page.
    Look at how my addon queries the WP dbase and returns the results. You can query XF dbase or do any thing else you need.


    http://xenforo.com/community/resources/wordpress-article-displayed-as-xenforo-page.2026/
     
  11. abnvet

    abnvet Active Member

    I get what you mean... Then my issue sits as when I echo some results out it displays the correct stuff but at the top of the page above the header. Does that make sense?
     
  12. EasyTarget

    EasyTarget Well-Known Member

    I do. That's why you need to hook into the template. You need your .php file to be called at the correct time. Your .php output is being sent to the browser before output buffering has been turned on. Or you are using print_r.

    If you let us know exactly what you are trying to do we can give you some suggestions on how to implement it.
     
  13. AndyB

    AndyB Well-Known Member

    You need to put the xen:callback tag at the position (in your template) where you want the echo to occur.
     
  14. abnvet

    abnvet Active Member

    Thanks so much for the replies so far!

    In a nutshell, I want to do this..
    1. query and echo all my user groups
    2. within that I want to query and echo my members in the groups.

    I.E.
    $connect = new connect();
    $result = $connect->query("SELECT STMT");
    while($row = $connect->fetchassoc($result)) {
    echo "<div>{$row['group']}<div>";
    $connect1 = new connect();
    $result1 = $connect1->query("SELECT STMT");
    while($row1 = $connect1->fetchassoc($result1)) {
    echo "<div>Title:{$row1['title']}</div>";
    }
    echo "</div>";
    }

    The result..

    Group Name
    Member
    Member
    Group Name
    Member

    Etc.

    This is so basic for what the end result will be but you'll get what I mean. I tried using the xen:callback tag in a blank template and it ended up at the top of the page.
     
  15. EasyTarget

    EasyTarget Well-Known Member

  16. abnvet

    abnvet Active Member

    Thanks for the reply. I will take a look.
     

Share This Page