Announcement

Collapse
No announcement yet.

include all php code in a variable // eval()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • include all php code in a variable // eval()

    Hi.
    I'd like to include a large PHP code into a single variable. So I can use that variable in Styles & Templates >> Templates

    here's my PHP codes:
    PHP Code:
    echo "<table>";
    while(
    $comm mysql_fetch_array($comquery))
      {
        
    $commuserid $comm['USERID'];
        
    $commusername $comm['USERNAME'];
        
    $commtimeadded $comm['time_added'];
        
    $comment $comm['comment'];
        echo 
    "<tr>";
        echo 
    "<td rowspan='2' align='center'><a href='member.php?u=$commuserid'><img src='image.php?u=$commuserid' width='50' /><br>$commusername</a></td>";
        echo 
    "<td width='100%' align='right'><font size='2'>$commtimeadded</font></td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td height='100%'>$comment</td>";
        echo 
    "</tr>";
      }
    echo 
    "</table>"
    i want to express it by $vcomment. that means when i put $vcomment on a template, it'll show the result of those codes.

    i google it & found that it might possible with eval() function. but i cant do that myself. if so, can anyone plz write me the eval code of those php code ...plz

  • #2
    Here is the approach I would take:

    Create a new template:

    Styles & Templates -> Style Manager

    From the drop down menu next the the style you are using, select Add New Template

    Title: vcomment_bit

    Paste this code in the the large Template box:

    Code:
    <tr> 
    <td rowspan="2" align="center"><a href="member.php?u=$commuserid"><img src="image.php?u=$commuserid" width="50" /><br />$commusername</a></td> 
    <td width="100%"><div style="text-align: right; font-size: 10px">$commtimeadded</div></td> 
    </tr> 
    <tr> 
    <td>$comment</td> 
    </tr>
    Then Save.

    I would then create a plugin which would work something like this:


    Code:
     
    $vcomment = '';
    while($comm = mysql_fetch_array($comquery)) 
    { 
    $commuserid = $comm['USERID']; 
    $commusername = $comm['USERNAME']; 
    $commtimeadded = $comm['time_added']; 
    $comment = $comm['comment'];
     
    eval('$vcomment .= "' . fetch_template('vcomment_bit') . '";');
    }
    For displaying $vcomment, open the template you are planning on having it show and add:

    Code:
    <if condition="$vcomment">
    <table>
    $vcomment
    </table>
    </if>
    Last edited by DoE; Fri 5th Jun '09, 5:09am.

    Comment


    • #3
      thank you very much. its working fine. i applied this on many codes & they r working

      but cant do it with this file below. its named home.php
      here's the full code of this page.

      can u plz integrate it with vBulletin Templates. So i can put the codes under echo in a template & put that on a variable like $home_bit & use that variable on any other template.

      NB: pagination class file attached.

      CODE REMOVED

      can u plz help with this one

      NB: Here's two kinds of extra code used.
      first is to add pagination. (it shows 6 item per page on example)
      second, to limit column number in SQL result...it autometically add a row when limited column number is genarated. like the example hav 3 column per row.

      plz see the attachment below
      Attached Files
      Last edited by MyPornLife.info; Sat 6th Jun '09, 8:39am.

      Comment


      • #4
        ^^^ edited. i attached some file & give there full codes. someone plz help me

        Comment


        • #5
          Supplying the code you need would be against site rules, so it would be best to ask at vBulletin.org. But if I understand correctly of what you wanted, the eval example I posted above is the easiest and best way for you to go. You should be able to modify it for your needs.

          Comment


          • #6
            guys. no problem...its done

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...
            X