MyBB Hacks

Full Version: PHP in Templates / Complex Templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(11-25-2011 07:17 AM)RateU Wrote: [ -> ]You can try to check by using $forum['fid']. Something like this:

Code:
<if $forum['fid'] == x then>
Codes for forum id = x here
<else>
Codes for other forum ids here
</if>


If it's a complex modification, personally, I prefer using XThreads for that.


Got it working, used this and worked a treat! Thanks!

I'm a bit of a novice and I was wondering how to use the conditionals to create more than two different codings?

IE for the moment I can have:
<if id = 1>
First template
</else>
Second template
</if>

But what if I wanted to have eight different templates? How would I go about doing that? I've tried just adding more if conditionals within it but it doesn't work.
Nesting?

Code:
<if $forum['fid'] == 1 then>
 ID 1
<else>
  <if $forum['fid'] == 2 then>
   ID 2
  <else>
    <if $forum['fid'] == 3 then>
     ID 3
    <else>
     something else
    </if>
  </if>
</if>

Or reduce the clutter with elseif's

Code:
<if $forum['fid'] == 1 then>
 ID 1
<elseif $forum['fid'] == 2 then>
 ID 2
<elseif $forum['fid'] == 3 then>
 ID 3
<else>
 no, I'm not going to put any more IDs
</if>

(11-25-2011 03:45 PM)ZiNgA BuRgA Wrote: [ -> ]Nesting?

Code:
<if $forum['fid'] == 1 then>
 ID 1
<else>
  <if $forum['fid'] == 2 then>
   ID 2
  <else>
    <if $forum['fid'] == 3 then>
     ID 3
    <else>
     something else
    </if>
  </if>
</if>

Or reduce the clutter with elseif's

Code:
<if $forum['fid'] == 1 then>
 ID 1
<elseif $forum['fid'] == 2 then>
 ID 2
<elseif $forum['fid'] == 3 then>
 ID 3
<else>
 no, I'm not going to put any more IDs
</if>


Perfect! Thanks so much Smile
Hello Zinga, really good job. Thanks!
I read that the code to extract data from the database is the follow. How do I set it to extract all rows from db?

Quote:{$attachment['icon']}&nbsp;&nbsp;<a href="attachment.php?aid={$attachment['aid']}" target="_blank">{$attachment['filename']}</a> ({$lang->postbit_attachment_size} {$attachment['filesize']} / {$lang->postbit_attachment_downloads} {$attachment['downloads']}
<?php

   $affected_fids = explode(',', $mybb->settings['newpoints_atcost_forums']);
   if (in_array($fid, $affected_fids)){

   $attach_id = $attachment['aid'];
   $attach_check = $db->query("SELECT * FROM mybb_newpoints_attachments WHERE AID='$attach_id'");
   $rows = $db->num_rows($attach_check);
   if ($rows > 0){
    $attach_cost = $db->fetch_field($attach_check, "cost");
    $attachment_cost_points = "/ <font color='red'>Cost:</font> ".$attach_cost;
}
}
?>
)

(12-12-2011 05:07 AM)FabrizioCo Wrote: [ -> ]How do I set it to extract all rows from db?
Use looping, like while?
(12-13-2011 01:13 AM)RateU Wrote: [ -> ]
(12-12-2011 05:07 AM)FabrizioCo Wrote: [ -> ]How do I set it to extract all rows from db?
Use looping, like while?

I used this code, but it doesn't work. I'm not good in object-oriented programming.

Quote:$query_2 = $db->query("SELECT * FROM voto_voti WHERE id_user = '$userid'");
$number_2 = $db->num_rows($query_2);

$i = 0;

if ($number_2 > 0){          
while ($number_2 > $i){          
$id_domanda = $db->fetch_field($query_2, "id_domanda");
$i++;
}
}
}
If you are really sure that it is rows, not columns in one row only, maybe something like this:

PHP Code:
while ($mydata = $db->fetch_array($query_2)){
// $mydata array here
}

(12-13-2011 04:06 AM)FabrizioCo Wrote: [ -> ]I used this code, but it doesn't work. I'm not good in object-oriented programming.
MyBB is pretty much all procedural.  The only link with OO is a few classes, which basically just act as fancy functions.

Although your code should work (as far as the loop is concerned), assuming you're using the data somewhere.
Hi, i need help with this code :

PHP Code:
$balance = mysql_query("SELECT `balance` FROM iconomy WHERE `username` = '{$mybb->user[\'fid4\']}'");
echo mysql_real_escape_string($balance); 

Cause MyBB is telling me it have a security issue :/
And i don't really see how i can fix it Frown

Can you help me please ?

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Reference URL's