Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Pulling a DB looping it as options

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
Bloodmorphed
Smarty Rookie


Joined: 20 Aug 2017
Posts: 8

PostPosted: Sun Aug 20, 2017 2:08 am    Post subject: Pulling a DB looping it as options Reply with quote

I have a table that is only 2 columns (id, name).
I got this to work yesterday with just name and after changing it i cant get it to work again.

Code:

        else
        {
          $query = $this->db->execute('SELECT * FROM `<ezrpg>mobs`');
          $mobs = $this->db->fetchAll($query);
          $this->tpl->display('battle.tpl');
        }

That's my PHP file.

Heres how I'm using it in template
Code:

  <form method="post" action="index.php?mod=Battle">
    <select name="selection">
      {foreach from=$mobs item=mob}
        <option value="{$mob->name}">{$mob->name}({$mob->id})</option>
      {/foreach}
    </select>
    <input name="battle_mob" type="submit" value="Fight" class="button" />
  </form>


i tried doing a while loop and assigning, individually and separately but to no avail. Any ideas would be wonderful![/code]
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sun Aug 20, 2017 3:59 am    Post subject: Reply with quote

I am not familiar with the syntax you are using. I will make several assumptions.

Apart from the assumptions, add {debug} to the template and let the browser open a popup window. Make sure $mobs has been assigned to the template variable "mobs". If it has, it will be shown in the debug popup.
Back to top
View user's profile Send private message
Bloodmorphed
Smarty Rookie


Joined: 20 Aug 2017
Posts: 8

PostPosted: Sun Aug 20, 2017 5:02 am    Post subject: Reply with quote

Well, that was easy. assigning it worked, I could have sworn i had done it multiple times. I must have done a mistype or something.

Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP