Advertisement:

Author Topic: How do I echo Out Data Fetched from database in custom template  (Read 280 times)

Offline mattizzy

  • Semi-Newbie
  • *
  • Posts: 29
I guess I may be disturbing but I still have a problem.

I want to use the output of this in my custom template but the array is automatically giving each messages a digit.
I used print_r($context['ft']) to check this.

 array([0] => array([subject] => test [body] => how to yest) [1] => array([subject] => honey [body] => how to honey))
Let's imagine that's all the posts I've got (2).

I want to get them such that if I use

echo '<div>'.$context['subject'] . $context['body'].'</div>';
It'll style each individual posts.

I can't call all the posts with

 $context['ft'][0]['subject']
$context['ft'][1][body']

$context['ft'][1]['subject']
$context['ft'][1]['body']


Here is the main code I used
<?
global $context;
$context['ft'] = array();
$query = $smcFunc['db_query']('', "SELECT * FROM {db_prefix}messages");
while ($row = $smcFunc['db_fetch_assoc']($query))
{
   $context['ft'][]  = array(
      'id' => $row['id_msg'],
                'subject' => $row['subject'],
      'body' => $row['body'],
   );
}


Online SychO

  • Jr. Member
  • **
  • Posts: 225
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: How do I echo Out Data Fetched from database in custom template
« Reply #1 on: July 08, 2018, 04:26:10 AM »
Use a foreach Loop ?

Code: [Select]
foreach($context['ft'] as $id=>$data) {
     echo '<div>'.$data['subject'] . $data['body'].'</div>';
}
Lazarus Responsive&Modern SMF Theme

SMF Hall Of Fame Mod

Offline mattizzy

  • Semi-Newbie
  • *
  • Posts: 29
Re: How do I echo Out Data Fetched from database in custom template
« Reply #2 on: July 08, 2018, 05:20:38 AM »
Thanks, I'll test it