Log in

View Full Version : How do I set variables?


Sketch
08-02-2002, 03:23 PM
Simple question, but elusive to me. How would I define a new variable to be used in a template.

Say I wanted to use $aaron and have a new bit that would display "Aaron is AwesomE!" wherever I put that in my templates.

In a similar vein, what if I wanted to use some PHP if/else to determine if a variable is set and if it is display it and if it is not, do not. An example of this would be in the postbit of my forum http://forums.livetheworship.com where I added $post[field7] (CD currently being played) to my postbit. I was trying to figure out how to test to see if a user set anything and if they did, display that variable and if they did not, then it would not display at all. Since I couldn't figure it out I had to settle on using (nothing) in my table for field7. Any ideas how to do these things.

In Summary:
1. how Do I add a new bit and then use it in the template system?
2. How do I set a variable in PHP and then use it in the templates?

Thanks.
Aaron

PS. If I can figure these simple things out, whole new worlds of mids will open up to me.

okrogius
08-02-2002, 05:01 PM
<?php

$variable = 'something';

?>

okrogius
08-02-2002, 05:06 PM
new bit code:

<?php

$bit = eval("all the template proccessing code, lookup form any file");

?>

Sketch
08-02-2002, 05:15 PM
ummm....not sure what you mean. Sorry. I know PHP and I understand eval() but I don't know how you're saying to work this....mind explaining a bit more? :) Thanks.

Aaron

DrkFusion
08-02-2002, 05:33 PM
I am guessing you put the following after maybe if statement or something
eval("\$aaron = \"".gettemplate('aaron_template')."\";");
in aaron_tempalte it would have the Aaron is cool, and then whatever file you put that in, like index.php put $aaron in the template, and it will say Aaron is cool.

I am taking a shot in the dark here.

Sketch
08-02-2002, 05:46 PM
I'll try it again, but that's what I thought too and it didn't seem to work. I tried it with like something like $x = 1; without any kind of if/else statement....just plain hardcoded variable, and then did

eval("\$x = \"".gettemplate('postbit')."\";");
and put $x in the template and it didn't seem to do much of anything....nothing was displayed. That's why I'm so confused.

Aaron

Sketch
08-03-2002, 08:08 PM
LOL....

This SUCKS!

Okay, This is what is in my showthread.php at the very end of the file:

//*********************Custom Field Hack********************
$tid = $thread[postuserid];
$customsql=mysql_query("SELECT * FROM userfield WHERE userid = '$tid'") or die(mysql_error());

while($custom=mysql_fetch_array($customsql)){

$field7 = $custom['field7'];

if($field7 == NULL)
{
$cdnow = "";
}
else
{
$cdnow = "<b>CD I am Playing:</b> <br>$field7";
}

eval("\$cdnow = \"".gettemplate('postbit')."\";");
}
//************************************************** ********
eval("dooutput(\"".gettemplate("showthread")."\");");
?>

And my postbit portion:

<b>$post[avatar]</b>
<normalfont><br>
<b>$post[username]</b>
</normalfont><br>
<smallfont>
$post[usertitle]<br>
$post[hasaward]
</smallfont><br><br>
<!---This was put here to see if $post[field7] would get to the page...it does
<smallfont>
<b>CD I am Playing:</b>
<br>$post[field7]</smallfont>
--->
<!---this should be what is displayed but it's not --->
$cdnow


So how do I get $cdnow to the screen???

Chris M
08-03-2002, 08:46 PM
I think this should be at the end of the file :

//*********************Custom Field Hack********************
$tid = $thread[postuserid];
$customsql=mysql_query("SELECT * FROM userfield WHERE userid = '$tid'") or die(mysql_error());

while($custom=mysql_fetch_array($customsql)){

if($post[field7] == "") {
$cdnow = "";
} else {
eval("\$cdnow = \"".gettemplate('postbit_cdnow')."\";");
}

//************************************************** ********
eval("dooutput(\"".gettemplate("showthread")."\");");
?>

Then...Create a template called : postbit_cdnow
Contents :
CD I am Playing:</b><br>$post[field7]

Then in the postbit template, add "$cdnow" where you want it...

Satan

Sketch
08-03-2002, 09:37 PM
yeah I actually changed that in my php al;ready. Still doesn't work. And in the postbit, I am using $cdnow. Notice the $post[field7] deal is in comments...

Aaron

Link14716
08-04-2002, 01:19 AM
try using $post[cdnow] in your postbit. I doubt it matters, but :D

Sketch
08-04-2002, 03:03 AM
no that wouldn't and doesn't work. cdnow is not a field in the db so it wouldn't be a variable included in $post...

Aaron