Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat do you think about the quality of this php code?
    primarykey
    data
    text
    <p>What do you think about this code? </p> <p>I know this has html mixed with php. How can we separate html from php? What else needs to be done to improve the quality of this code?</p> <p>Hopefully some php experts here can help me out.</p> <p><strong>Edit:</strong></p> <p>Just wanted to add that in this particular code the business logic is already into separate files like the AppointmentManager class which takes care of everything related to appointments, creation deletion etc. etc. </p> <p>The code piece(manage.php) that i put here just displays the appointments details and allows for editing, canceling them.</p> <p>Now, i'm not sure what we call this page whether it's display logic or presentation logic or anything else.... but what i need to know is if it;s possible to further separate html and php?</p> <p>Can i do something for example to get this piece of html out of this file...</p> <pre><code>&lt;script language="JavaScript" src="ajax/core2.js"&gt;&lt;/script&gt; &lt;h2 align='center'&gt; Appointment Control Panel V 1.0&lt;/h2&gt; &lt;h2 align='center'&gt;Your Next Appointments&lt;/h2&gt; &lt;div id=detail&gt;&lt;/div&gt; </code></pre> <p>And similarly rest of it...... I mean completely separate html and php so that it's easy to maintian and extend the application.</p> <p>I don't want to use Smarty, i think it unnecessarily complicates things.</p> <p>Can i create some php functions that render this html when called and maybe put them into a common functions file like displayhtml.php?</p> <p>Any other better suggestions possibly?</p> <pre><code>&lt;?php /* * manage.php * * Author: Bob : 2010-11-11 * */ ob_start(); $page_title = "Appointments Management"; require_once('appts/coreincs.inc'); require_once('appts/pagetop.inc'); $am = AppointmentManager::getInstance(); $appts = $am-&gt;getPendingAppointments($g_userID); ?&gt; &lt;script language="JavaScript" src="ajax/core2.js"&gt;&lt;/script&gt; &lt;h2 align='center'&gt; Appointment Control Panel V 1.0&lt;/h2&gt; &lt;h2 align='center'&gt;Your Next Appointments&lt;/h2&gt; &lt;div id=detail&gt;&lt;/div&gt; &lt;?php if ($appts === NULL) { echo &lt;&lt;&lt;EOEMPTY &lt;p align='center'&gt; You have no upcoming appointments. &lt;/p&gt; EOEMPTY; } else { /** * List the appointments. Start the table. */ echo &lt;&lt;&lt;EOT &lt;table align='center' width='80%' border='0' cellspacing='0' cellpadding='3' class='apptTable'&gt; &lt;tr&gt; &lt;td width='25%' class='apptDispHeader'&gt;When:&lt;/td&gt; &lt;td width='30%' class='apptDispHeader'&gt;Title:&lt;/td&gt; &lt;td width='15%' class='apptDispHeader'&gt;Action:&lt;/td&gt; &lt;td width='25%' class='apptDispHeader'&gt;Where:&lt;/td&gt; &lt;/tr&gt; EOT; /** * Zip through all the appointments and print them out. */ foreach ($appts as $appt) { //if ($appt-&gt;StartTime-&gt;sameDay($appt-&gt;EndTime)) //{ $start = $appt-&gt;FullTimestart; $end = $appt-&gt;FullTimeend; echo &lt;&lt;&lt;EOAPPT &lt;tr&gt; &lt;td&gt;$start ==&gt; $end&lt;/td&gt; &lt;td&gt; &lt;div id=title_{$appt-&gt;AppointmentID} loaded="t_{$appt-&gt;AppointmentID}"&gt; &lt;div id=title_{$appt-&gt;AppointmentID}_t_{$appt-&gt;AppointmentID}&gt; &lt;a class='apptDispLink' href='showappt.php?aid={$appt-&gt;AppointmentID}'&gt; {$appt-&gt;Title} &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt;&lt;a onclick=Core2.loadXMLDoc('ajaxrequest.php?aid={$appt-&gt;AppointmentID}',['edit'],['detail'],['edit_form_{$appt-&gt;AppointmentID}'],"reLoad","hide_all")&gt;Edit&lt;/a&gt; | &lt;a onclick=Core2.loadXMLDoc('cancel.php?aid={$appt-&gt;AppointmentID}',['delete'],['title_{$appt-&gt;AppointmentID}'],['cancel_{$appt-&gt;AppointmentID}'],"reLoad","hide_all")&gt;Cancel&lt;/a&gt;&lt;/td&gt; &lt;td&gt; {$appt-&gt;Location} &lt;/td&gt; &lt;/tr&gt; EOAPPT; } /** * Close out the Table: */ echo &lt;&lt;&lt;EOT &lt;/table&gt; &lt;iframe name=main width="0" height="0" marginwidth="1" marginheight="1" scrolling="no" border="0" frameborder="0"&gt;&lt;/iframe&gt; EOT; } require_once('appts/pagebottom.inc'); ob_end_flush(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload