I have a website that I'm trying to convert over to PHP to help solve some complexity issues over how large my site is becoming.
The biggest problem I've been having is with pages I use to display my record (ie vinyl) collection. A lot of information is duplicated in several spot, and it makes it hard to make changes.
For example, I used to use this as a template to fill out for EVERY record in my collection (a few thousand now, I believe).
<TR BGCOLOR="#FFFFFF">
<TD WIDTH="125"><FONT>Artist</FONT></TD>
<TD WIDTH="250"><FONT>Title</FONT></TD>
<TD WIDTH="125"><FONT>Label</FONT></TD>
<TD WIDTH="100"><FONT>LabelCode</FONT></TD>
<TD WIDTH="50"><FONT>BPM</FONT></TD>
</TR>
I recently needed to change the TD WIDTH on all these, which was a MAJOR hassle to do, because this template was used on at least 6 different pages.
I found some info about how I could use includes to add some variables (well, defined constants really) to each of the 6 pages so I could change all 6 from one file by doing this:
<?php echo TR1 ?>
_ <?php echo TD1 ?>Artist</FONT></TD>
_ <?php echo TD2 ?>Title</FONT></TD>
_ <?php echo TD3 ?>Label</FONT></TD>
_ <?php echo TD4 ?>LabelCode</FONT></TD>
_ <?php echo TD5 ?>BPM</FONT></TD>
</TR>
Up until this point, everything is all good. I had an idea to have one very large text file with ALL my records and use PHP to define each record as a variable, so that when a record is duplicated on several pages, ie a listing that I own it on one page, another on a page that lists out all the DJ mixes I've created, and a third that lists my weekly DJ charts of my favorite tunes (the latter is where it's needed the most, as one record can be listed on that page several times).
So I tried to do this:
<?php
define("VARIABLE1", "\n
<?php echo TR1 ?>
_ <?php echo TD1 ?>Artist</FONT></TD>
_ <?php echo TD2 ?>Title</FONT></TD>
_ <?php echo TD3 ?>Label></FONT></TD>
_ <?php echo TD4 ?>LabelCode</FONT></TD>
_ <?php echo TD5 ?>BPM</FONT></TD>
</TR>\n");
?>
and then on the pages where this info is needed, do this:
<?php echo VARIABLE1 ?>
<?php echo VARIABLE2 ?>
..
etc
..
<?php echo VARIABLE99 ?>
but it doesn't seem to work. Is there anything obvious that I'm doing wrong? My first guess is that there can't be any nesting of echo commands, like the ones that are used to create the TD WIDTH information I need, which looks like this:
<?php
define("TD1", "<TD WIDTH=105><FONT>");
?>
<?php
define("TD2", "<TD WIDTH=335><FONT>");
?>
<?php
define("TD3", "<TD WIDTH=95><FONT>");
?>
<?php
define("TD4", "<TD WIDTH=75><FONT>");
?>
<?php
define("TD5", "<TD WIDTH=40><FONT>");
?>
Any help would be appreciated, or if there is another direction I could do with this design, I'd love to hear about it!
Thanx,
Mitch