My Own Code

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?
 
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!
 
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.
 
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>
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?
 
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.
 
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.

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.
 
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.
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/
 
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.

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?
 
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.
 
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?

You need to put the xen:callback tag at the position (in your template) where you want the echo to occur.
 
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.
 
Back
Top Bottom