Bifter Posted July 7, 2008 Share Posted July 7, 2008 Hi all, Is it possible to improve the code below to 1) make it shorter and more manageable? and 2) make it into a string or function so I can call it multiple times: <?php echo "<table width=\"57%\" align=\"center\" cellpadding=5 class=bordered>"; echo "<tr><th>Total Lines Required </th>"; echo "<th>Total Extensions Required</th>"; echo "<th>Total Phones Required</th></tr>"; echo "<tr><td>"; echo "<div align=\"center\">"; echo NumLines (); echo "</td><td>"; echo "<div align=\"center\">"; echo TotalExtension (); echo "</td><td>"; echo "<div align=\"center\">"; echo NumPhones (); echo "</div>"; echo "</td></tr>"; echo "</table>" . "<br />"; echo "</div>"; echo "<div class=\"page\">"; echo "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr>"; echo "<td align=\"center\"><table cellpadding=5 width=98% class=bordered bgcolor=#EFEFEF style=\"margin-bottom: 10px\">"; echo "<tr>"; echo "<th colspan=4><img src=\"http://www.flipsolutions.co.uk/images/quoting/avaya.png\" width=\"120\" height=\"49\"></th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"2\" class=label><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td><div align=\"center\"><strong>Part</strong></div></td>"; echo "<td width=\"25%\"><div align=\"center\"><strong>Price Per Unit </strong></div></td>"; echo "<td width=\"26%\"><div align=\"center\"><strong>Amount Required </strong></div></td>"; echo "<td width=\"17%\"><div align=\"center\"><strong>Line Total </strong></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Main Unit </div></td>"; echo "<td><div align=\"center\">£406.00</div></td>"; echo "<td><div align=\"center\">1</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo MainUnit (); echo "<br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Analogue Card </div></td>"; echo "<td><div align=\"center\">£232.00</div></td>"; echo "<td><div align=\"center\">"; echo AnaNumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo AnaLineTotal (); echo "<br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">ISDN2e Card </div></td>"; echo "<td><div align=\"center\">£275.00</div></td>"; echo "<td><div align=\"center\">"; echo ISDN2NumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo ISDN2LineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">ISDN30e Card </div></td>"; echo "<td><div align=\"center\">£530.00</div></td>"; echo "<td><div align=\"center\">"; echo ISDN30NumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo ISDN30LineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Digital Extension Card </div></td>"; echo "<td><div align=\"center\">£319.00</div></td>"; echo "<td><div align=\"center\">"; echo DigExtNumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo DigExtLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Analogue Extension Card </div></td>"; echo "<td><div align=\"center\">£145.00</div></td>"; echo "<td><div align=\"center\">"; echo AnaExtNumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo AnaExtLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Voicemail</div></td>"; echo "<td><div align=\"center\">£500.00</div></td>"; echo "<td><div align=\"center\">1</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo Voicemail (); echo "<br /><br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Basic Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/5402.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/5402_large.png\" /><br />Avaya 5402 Terminal</span></a> </div></div></td>"; echo "<td><div align=\"center\">£72.00</div></td>"; echo "<td><div align=\"center\">"; echo $BasicHand; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo BasPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Mid Range Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/5410.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/5410_large.png\" /><br />Avaya 5410 Terminal</span></a> </div></div></td>"; echo "<td><div align=\"center\">£152.00</div></td>"; echo "<td><div align=\"center\">"; echo $GeneralHand; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo MidPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Executive Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/5420.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/5420_large.png\" /><br />Avaya 5420 Terminal</span></a> </div></div></td>"; echo "<td><div align=\"center\">£218.00</div></td>"; echo "<td><div align=\"center\">"; echo $ExecHand; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo ExecPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\"><b>Hardware Total</b></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "<b>" . "£"; echo HardTotal () . "<br />" . "</b>"; echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Installation</div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo InstallLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Training</div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo TrainLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td> </td>"; echo "<td> </td>"; echo "<td><div align=\"center\">Total</div></td>"; echo "<td><div align=\"center\">"; echo "<b>£</b>"; echo "<b>"; echo Total (); echo "</b>"; echo "</div></td>"; echo "</tr>"; echo "</table></td>"; echo "</tr>"; echo "</table></td>"; echo "<td align=\"center\"><table cellpadding=5 width=98% class=bordered bgcolor=#EFEFEF style=\"margin-bottom: 10px\">"; echo "<tr>"; echo "<th colspan=4><img src=\"http://www.flipsolutions.co.uk/images/quoting/cisco.png\" width=\"89\" height=\"49\"></th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"2\" class=label><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td><div align=\"center\"><strong>Part</strong></div></td>"; echo "<td width=\"25%\"><div align=\"center\"><strong>Price Per Unit </strong></div></td>"; echo "<td width=\"26%\"><div align=\"center\"><strong>Amount Required </strong></div></td>"; echo "<td width=\"17%\"><div align=\"center\"><strong>Line Total </strong></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Main Router</div></td>"; echo "<td><div align=\"center\">£1,500.00</div></td>"; echo "<td><div align=\"center\">1</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoMainUnit (); echo "<br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">ISDN2e Card </div></td>"; echo "<td><div align=\"center\">£200.00</div></td>"; echo "<td><div align=\"center\">"; echo CiscoISDN2NumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoISDN2LineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">ISDN30e Card </div></td>"; echo "<td><div align=\"center\">£600.00</div></td>"; echo "<td><div align=\"center\">"; echo CiscoISDN30NumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoISDN30LineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Switch</div></td>"; echo "<td><div align=\"center\">£1,200</div></td>"; echo "<td><div align=\"center\">"; echo CiscoDigExtNumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoDigExtLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Voicemail</div></td>"; echo "<td><div align=\"center\">£600.00</div></td>"; echo "<td><div align=\"center\">1</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoVoicemail (); echo "<br /><br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Basic Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/7906.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/7906_large.png\" /><br />Cisco 7906G Handset</span></a> </div></div></td>"; echo "<td><div align=\"center\">£135.00</div></td>"; echo "<td><div align=\"center\">"; echo $BasicHand ; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoBasPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Mid Range Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/7941.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/7941_large.png\" /><br />Cisco 7941G Handset</span></a> </div></div></td>"; echo "<td><div align=\"center\">£192.00</div></td>"; echo "<td><div align=\"center\">"; echo $GeneralHand ; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoMidPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Executive Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/7970.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/7970_large.png\" /><br />Cisco 7970G Handset</span></a> </div></div></td>"; echo "<td><div align=\"center\">£297.00</div></td>"; echo "<td><div align=\"center\">"; echo $ExecHand ; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoExecPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\"><b>Hardware Total</b></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "<b>" . "£"; echo CiscoHardTotal () . "<br />" . "</b>"; echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Installation</div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoInstallLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Training</div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo CiscoTrainLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td> </td>"; echo "<td> </td>"; echo "<td><div align=\"center\">Total</div></td>"; echo "<td><div align=\"center\">"; echo "<b>£</b>"; echo "<b>"; echo CiscoTotal (); echo "</b>"; echo "</div></td>"; echo "</tr>"; echo "</table></td>"; echo "</tr>"; echo "</table></td>"; echo "<td align=\"center\"><table cellpadding=5 width=98% class=bordered bgcolor=#EFEFEF style=\"margin-bottom: 10px\">"; echo "<tr>"; echo "<th colspan=4><img src=\"http://www.flipsolutions.co.uk/images/quoting/samsung.png\" width=\"114\" height=\"49\"></th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"2\" class=label><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td><div align=\"center\"><strong>Part</strong></div></td>"; echo "<td width=\"25%\"><div align=\"center\"><strong>Price Per Unit </strong></div></td>"; echo "<td width=\"26%\"><div align=\"center\"><strong>Amount Required </strong></div></td>"; echo "<td width=\"17%\"><div align=\"center\"><strong>Line Total </strong></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Main Unit </div></td>"; echo "<td><div align=\"center\">£995.00</div></td>"; echo "<td><div align=\"center\">1</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamMainUnit (); echo "<br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Analogue Card </div></td>"; echo "<td><div align=\"center\">£345.00</div></td>"; echo "<td><div align=\"center\">"; echo SamAnaNumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamAnaLineTotal (); echo "<br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">ISDN2e Card </div></td>"; echo "<td><div align=\"center\">£395.00</div></td>"; echo "<td><div align=\"center\">"; echo SamISDN2NumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamISDN2LineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">ISDN30e Card </div></td>"; echo "<td><div align=\"center\">£530.00</div></td>"; echo "<td><div align=\"center\">"; echo SamISDN30NumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamISDN30LineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Digital Extension Card </div></td>"; echo "<td><div align=\"center\">£295.00</div></td>"; echo "<td><div align=\"center\">"; echo SamDigExtNumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamDigExtLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Analogue Extension Card </div></td>"; echo "<td><div align=\"center\">£295.00</div></td>"; echo "<td><div align=\"center\">"; echo SamAnaExtNumReq (); echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamAnaExtLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Voicemail</div></td>"; echo "<td><div align=\"center\">£1,000.00</div></td>"; echo "<td><div align=\"center\">1</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamVoicemail (); echo "<br /><br /></div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Basic Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/5007s.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/5007s_large.png\" /><br />Samsung DS-5007s Handset</span></a> </div>"; echo "<td><div align=\"center\">£100.00</div></td>"; echo "<td><div align=\"center\">"; echo $BasicHand; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamBasPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Mid Range Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/5014s.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/5014s_large.png\" /><br />Samsung DS-5014s Handset</span></a> </div>"; echo "<td><div align=\"center\">£150.00</div></td>"; echo "<td><div align=\"center\">"; echo $GeneralHand; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamMidPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Mid Range Handset <div class=\"gallerycontainer\"> <a class=\"thumbnail\" href=\"#thumb\"><img src=\"http://www.flipsolutions.co.uk/images/quoting/5038s.png\" width=\"98px\" height=\"81px\" border=\"0\" /><span><img src=\"http://www.flipsolutions.co.uk/images/quoting/5038s_large.png\" /><br />Samsung DS-5038s Handset</span></a> </div></td>"; echo "<td><div align=\"center\">£230.00</div></td>"; echo "<td><div align=\"center\">"; echo $ExecHand; echo "</div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamExecPhoneLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\"><b>Hardware Total</b></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "<b>" . "£"; echo SamHardTotal () . "<br />" . "</b>"; echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Installation</div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamInstallLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td><div align=\"center\">Training</div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\"></div></td>"; echo "<td><div align=\"center\">"; echo "£"; echo SamTrainLineTotal (); echo "<br /</div></td>"; echo "</tr>"; echo "<tr>"; echo "<td> </td>"; echo "<td> </td>"; echo "<td><div align=\"center\">Total</div></td>"; echo "<td><div align=\"center\">"; echo "<b>£</b>"; echo "<b>"; echo SamTotal (); echo "</b>"; echo "</table></td>"; echo "</tr>"; echo "</table></td>"; echo "</tr>"; echo "</table>"; echo "</div>"; ?> Thanks for taking the time to look at this and if you can help I would appreciate it, as I’m trying to learn php by myself and its proving a bit of a brain ache!!! (edited by kenrbnsn to make the PHP code standout better) Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 7, 2008 Share Posted July 7, 2008 If you want some advice, use a PHP framework, something of a MVC (Model, View, Controller) architecture. It should help you manage your code, and help seperate large blocks of your code from the initial design. My personal favorite is Zend Framework, or Drupals built-in framework. Quote Link to comment Share on other sites More sharing options...
Bifter Posted July 7, 2008 Author Share Posted July 7, 2008 Hi Wolphie, Will Zend allow me to do the second part of the question? ie make the html table into a function? also is it possible to embed functions within a html table then call the whole table as one fuction - if that makes sense? Cheers, B Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 7, 2008 Share Posted July 7, 2008 It is possible to return HTML inside a PHP function yes, although I don't see why you would want to return an entire table in PHP. I can understand if you actually wanted to populate a table using PHP. Quote Link to comment Share on other sites More sharing options...
Bifter Posted July 7, 2008 Author Share Posted July 7, 2008 Basicly its a quoting tool whereby someone inserts quantities of different products into a form, then hits submit and the quote is displayed in the browser, then I want to give them the option to email the quote to themselves, so by creating the whole table as a function I can call the output multipul times - is this correct? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.