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: 885
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:

international 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.'',

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

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

$amFunc['db_free_result']($result);

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:

international 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',

Array(
)
);

$return3 = array();

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

$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:

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




 
> TOPIC: SMF Query - Getting Data From Database
 

▲ TOP


International Discussions Coded by: BGID®
ALL RIGHTS RESERVED Copyright © 1999-2024
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,