MyBB Community Forums
Write PHP codes in Global Templates? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: Write PHP codes in Global Templates? (/thread-221244.html)



Write PHP codes in Global Templates? - ahmedwaill - 12-28-2018

Hello MyBB Community, 
    i just wanna ask is there a way to write "While Statement" in MyBB Global Temlpates ?!
i got a template that reads some records from MySQL Database such as "uploaded files names, Size, location" and shows it in a table view, but in order to make it read all the records i have to use this code:
<tbody>
  <?php
  	while($r = mysqli_fetch_assoc($result)){
   ?>
    <tr>
      <th scope="row"><?php echo $r['id'] ?></th>
      <td><?php echo $r['name'] ?></td>
      <td><?php echo $r['size'] ?></td>
      <td><?php echo $r['type'] ?></td>
      <td><a href="<?php echo $r['location'] ?>">View</a></td>
      <td><a href="#" onclick='deleteItem(<?php echo $r['id'] ?>)'>Delete</a></td>
    </tr>
    <?php
    }
    ?>
  </tbody>

but since i can't use php it always gives error.
i tried to use the plugin "[url=http://mybbhacks.zingaburga.com/][/url]PHP and Template Conditionals" but "While Statement" doesn't work in it , it got only "if" statement work..
and if i use "if" statement in here it shows only the first record ..
i hope you can help me guys,
here is a link to preview :
http://dmo4arab.eb2a.com/forum/view.php


 thanks in advance.


RE: Write PHP codes in Global Templates? - .m. - 12-29-2018

looks like while already works with the plugin (eg.)

[make a search with while as the keyword in that thread
search within the thread is available near bottom right of thread page]


RE: Write PHP codes in Global Templates? - ahmedwaill - 12-29-2018

alright thanks a lot , will try it and give you my feedback

actually not working , 

i've tried the code like that 
  <?php
  	while($r = mysqli_fetch_assoc($result)){
   ?>
    <tr>
<th class="trow5" scope="row">{$r['id']}</th>
      <td class="trow5">{$r['name']}</td>[/font][/size]
      <td class="trow5">{$r['size']}</td>[/font][/size]
      <td class="trow5">{$r['type']}</td>[/font][/size]
      <td class="trow5"><a href="{$r['location']}">View</a></td>[/font][/size]
      <td class="trow5"><a href="#" onclick="deleteItem({$r['id']})">Delete</a></td>[/font][/size]
      <td class="trow5"><a href="#" onclick="myFunction()">Rename</a></td>[/font][/size]
      <td class="trow5"><form align><a id="renameform" style="display: none;color:black;text-align: -webkit-center;width: fit-content;max-width: fit-content;">New Name: <input type="text" id="newname2" name="newname" style="width: 120px;"></a><button href="#" id="renameform2" style="display: none;margin-top: 5px;" onclick="renameItem({$r['id']},newname2)">Rename</a>[/font][/size]
	</form></td>
    </tr>
    <?php
    }
    ?>
and 
that's the what appears when i run the page 
[attachment=41380]

 , and i've tried it like that although
while ($r = mysqli_fetch_assoc($result)){
<tr>
      <th class="trow5" scope="row">{$r['id']}</th>
      <td class="trow5">{$r['name']}</td>
      <td class="trow5">{$r['size']}</td>
      <td class="trow5">{$r['type']}</td>
      <td class="trow5"><a href="{$r['location']}">View</a></td>
      <td class="trow5"><a href="#" onclick="deleteItem({$r['id']})">Delete</a></td>
	  <td class="trow5"><a href="#" onclick="myFunction()">Rename</a></td>
      <td class="trow5"><form align><a id="renameform" style="display: none;color:black;text-align: -webkit-center;width: fit-content;max-width: fit-content;">New Name: <input type="text" id="newname2" name="newname" style="width: 120px;"></a><button href="#" id="renameform2" style="display: none;margin-top: 5px;" onclick="renameItem({$r['id']},newname2)">Rename</a>
	</form></td>	
</tr>
}
that's the what appears when i run the page 
[attachment=41379]


RE: Write PHP codes in Global Templates? - .m. - 12-29-2018

^ reg. above given second error message
please see few search results => "result could not be converted to string"


RE: Write PHP codes in Global Templates? - ahmedwaill - 12-29-2018

well as for the error message you're talking bout , the issue is that i didn't write <?php and ?> codes before and after the while statement ...
so that's not the issue


RE: Write PHP codes in Global Templates? - ahmedwaill - 12-30-2018

so anyone can help in that ?!


RE: Write PHP codes in Global Templates? - ahmedwaill - 12-31-2018

so guys anyone willing to help out ?!
**Happy New Year**


RE: Write PHP codes in Global Templates? - ahmedwaill - 01-02-2019

so guys it has been 2 days till now and no one could help , is there anyone can help ?


RE: Write PHP codes in Global Templates? - ahmedwaill - 01-10-2019

nvm solved it using this solution without using Global Templates
https://community.mybb.com/thread-148886-post-1052361.html#pid1052361