Jump to the post that solved this thread.
Solved: 5 Years, 10 Months, 4 Weeks ago Write PHP codes in Global Templates?
#1
Solved: 5 Years, 10 Months, 4 Weeks ago
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.
Reply
#2
Solved: 5 Years, 10 Months, 4 Weeks ago
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]
Reply
#3
Solved: 5 Years, 10 Months, 4 Weeks ago
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 
   

 , 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 
   
Reply
#4
Solved: 5 Years, 10 Months, 4 Weeks ago
^ reg. above given second error message
please see few search results => "result could not be converted to string"
Reply
#5
Solved: 5 Years, 10 Months, 4 Weeks ago
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
Reply
#6
Solved: 5 Years, 10 Months, 4 Weeks ago
so anyone can help in that ?!
Reply
#7
Solved: 5 Years, 10 Months, 4 Weeks ago
so guys anyone willing to help out ?!
**Happy New Year**
Reply
#8
Solved: 5 Years, 10 Months, 4 Weeks ago
so guys it has been 2 days till now and no one could help , is there anyone can help ?
Reply
#9
Solved: 5 Years, 10 Months, 4 Weeks ago
nvm solved it using this solution without using Global Templates
https://community.mybb.com/thread-148886...pid1052361
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)