SMF Query - Getting Data From Database

Smf Query Data Database - Computer Issues, Video Gaming - Posted: 4th Dec, 2019 - 3:45pm

Text RPG Play Text RPG ?

Posts: 2 - Views: 504
smf discussion Simple Machines Forums Software - array, arrays
26th Oct, 2019 - 1:38am / Post ID: #

SMF Query - Getting Data From Database

Sometimes you may need to insert your own code and / or retrieve info from SMF's DB. To do this you would do something like this:

Attached Image CODE

$result = $amFunc['db_query']('
SELECT m.id_comment,m.id_media,m.id_member, mem.id_member, mem.member_name
FROM {db_prefix}aeva_comments as m
LEFT JOIN {db_prefix}members AS mem ON (Mem.id_member = m.id_member)
WHERE m.id_comment ='.$theid.'',

'id_member' => 'id_member',
'member_name' => 'mem.member_name',
$row = $amFunc['db_fetch_assoc']($result);

$idmember = $row['id_member'];
$memname = $row['member_name'];


In this code, I am finding the last commentator's I'd from a defunct mod called "Aeva" and thus return his / her's name from the Membership table. I can then use $memname to display it.

Sponsored Links:
4th Dec, 2019 - 3:45pm / Post ID: #

Database Data - Query SMF

In the case where you need several rows of information for EACH row of a different query then you can do this:

Attached Image CODE

$sresult = $smcFunc['db_query']('','
SELECT id_topic,poster_time,id_member,poster_name
FROM {db_prefix}messages
WHERE id_topic ='.$theid.' order by poster_time DESC Limit 3',


$return3 = array();

While ($srow = $smcFunc['db_fetch_assoc']($sresult)){
$return3[] = array(
'memname' => $srow['poster_name'],

$temp_array = array();

Foreach ($return3 as $member3){
$temp_array[] = $member3['memname'];
$memname = implode(', ', $temp_array);

In the above $memname will give you the last 3 but if the last 3 is the same you may want to do without the repeats so in this case you can use:

Attached Image CODE
$memname = implode(', ', array_unique($temp_array));

Sponsored Links:

Comment Add Comment As A Guest
Important Guest, please be considerate by using the appropriate tags as well as checking your grammar before submitting or it will be deleted. See: Constructive Posting Policy.

# Characters:
# Words:
# Sentences:
# Paragraphs:
Reading Time:

Tip TIP: Press above button ONCE only. If you come back here via the [Back] button on your browser then you will need to click [More Options] button (below) first in order to re-enable your ability to Post.

> TOPIC: SMF Query - Getting Data From Database

International Discussions Coded by: BGID®
ALL RIGHTS RESERVED Copyright © 1999-2023
Disclaimer Privacy Report Errors Credits
This site uses Cookies to dispense or record information with regards to your visit. By continuing to use this site you agree to the terms outlined in our Cookies used here: Privacy / Disclaimer,