Results 1 to 6 of 6

Thread: html in PHP

  1. #1
    Join Date
    Jan 2011

    Exclamation html in PHP

    Hi! I'm having problems with the php file i'm working on.

    I'm supposed to make an html code work on php.
    Here's the html code:
    <script type="text/JavaScript">
    	function calcATable()
    		nB ="<table border='1'>";
    		nB+="	<tr>";
    		nB+="		<td>Year</td>";
    		nB+="		<td>Interest</td>";
    		nB+="		<td>Principal</td>";
    		nB+="		<td>Balance</td>";
    		nB+="	<tr>";
    		for (y=1; y<=n; y++)
    			nB+="	<tr>";
    			nB+="		<td>"+y+"</td>";
    			nB+="		<td align='right'>"+parseInt(aInterest*100)/100+"</td>";
    			nB+="		<td align='right'>"+parseInt(aPrincipal*100)/100+"</td>";
    			nB+="		<td align='right'>"+parseInt(lBalance*100)/100+"</td>";
    			nB+="	</tr>";
    		nB+="	<tr>";
    		nB+="		<td>Sum :</td>";
    		nB+="		<td align='right'>"+parseInt(sumInterest*100)/100+"</td>";
    		nB+="		<td align='right'>"+parseInt(sumPrincipal*100)/100+"</td>";
    		nB+="		<td>&nbsp;</td>";
    		nB+="	</tr>";
    	<div align="center">
    		<img src="up.png"><br>
    		<b>ABC Bank of Tacloban</b>
    		<caption>Loan Application Form<hr></caption>
    			<td align="right">Name of borrower :</td>
    			<td><input type="text" id="nBorr" size="30"></td>
    			<td align="right">Amount to be loaned :</td>
    			<td><input type="text" id="aLoaned" size="12"></td>
    			<td align="right">Term :</td>
    			<td><input type="text" id="tLoan" size="2"> years</td>
    			<td align="right">Interest rate :</td>
    			<td><input type="text" id="iLoan" size="5"> % per annum</td>
    			<td colspan="2"><hr></td>
    			<td align="right">Annuity :</td>
    			<td><input type="text" id="payLoan" size="12" readonly></td>
    			<td colspan="2"><hr></td>
    			<td colspan="2"><input type="button" value="Calculate" onClick="calcATable();"></td>
    	<div id="amortTable"></div>
    I tried to make it work on php. Here's my php code:
    	$b.="<script type='text/JavaScript'>";
    	$b.="	function calcATable()";
    	$b.="	{";
    	$b.="		aLoaned=document.getElementById('aLoaned').value;";
    	$b.="		i=document.getElementById('iLoan').value/100;";
    	$b.="		n=document.getElementById('tLoan').value;";
    	$b.="		annuity=(aLoaned*i)/(1-(1/Math.pow(1+i,n)));";
    	$b.="		document.getElementById('payLoan').value=parseInt(annuity*100)/100;";
    	$b.="		nB ='<table border='1'>';";
    	$b.="		nB+='	<tr>';";
    	$b.="		nB+='		<td>Year</td>';";
    	$b.="		nB+='		<td>Interest</td>';";
    	$b.="		nB+='		<td>Principal</td>';";
    	$b.="		nB+='		<td>Balance</td>';";
    	$b.="		nB+='	<tr>';";
    	$b.="		lBalance=aLoaned;";
    	$b.="		sumInterest=0;";
    	$b.="		sumPrincipal=0;";
    	$b.="		for (y=1; y<=n; y++)";
    	$b.="		{";
    	$b.="			aInterest=lBalance*i;";
    	$b.="			aPrincipal=annuity-aInterest;";
    	$b.="			lBalance-=aPrincipal;";
    	$b.="			sumInterest+=aInterest;";
    	$b.="			sumPrincipal+=aPrincipal;";
    	$b.="			nB+='	<tr>';";
    	$b.="			nB+='		<td>'+y+'</td>';
    	$b.="			nB+='		<td align='right'>'+parseInt(aInterest*100)/100+'</td>';";
    	$b.="			nB+='		<td align='right'>'+parseInt(aPrincipal*100)/100+'</td>';";
    	$b.="			nB+='		<td align='right'>'+parseInt(lBalance*100)/100+'</td>';";
    	$b.="			nB+='	</tr>';";
    	$b.="		}
    	$b.="		nB+='	<tr>';";
    	$b.="		nB+='		<td>Sum :</td>';";
    	$b.="		nB+='		<td align='right'>'+parseInt(sumInterest*100)/100+'</td>';";
    	$b.="		nB+='		<td align='right'>'+parseInt(sumPrincipal*100)/100+'</td>';";
    	$b.="		nB+='		<td>&nbsp;</td>';";
    	$b.="		nB+='	</tr>';";
    	$b.="		nB+='</table>';";
    	$b.="		document.getElementById("amortTable").innerHTML=nB;";
    	$b.="	}";
    	$b.="	<div align='center'>";
    	$b.="		<img src='up.png'><br>";
    	$b.="		<b>ABC Bank of Tacloban</b>";
    	$b.="	</div><hr>";
    	$b.="	<table>";
    	$b.="		<caption>Loan Application Form<hr></caption>";
    	$b.="		<tr>";
    	$b.="			<td align='right'>Name of borrower :</td>";
    	$b.="			<td><input type='text' id='nBorr' size='30'></td>";
    	$b.="		</tr>";
    	$b.="		<tr>";
    	$b.="			<td align='right'>Amount to be loaned :</td>";
    	$b.="			<td><input type='text' id="aLoaned" size='12'></td>";
    	$b.="		</tr>";
    	$b.="		<tr>";
    	$b.="			<td align='right'>Term :</td>";
    	$b.="			<td><input type='text' id='tLoan' size='2'> years</td>";
    	$b.="		</tr>";
    	$b.="		<tr>";
    	$b.="			<td align='right'>Interest rate :</td>";
    	$b.="			<td><input type='text' id='iLoan' size='5'> % per annum</td>";
    	$b.="		</tr>";
    	$b.="		<tr>";
    	$b.="			<td colspan='2'><hr></td>";
    	$b.="		</tr>";
    	$b.="		<tr>";
    	$b.="			<td align='right'>Annuity :</td>";
    	$b.="			<td><input type='text' id='payLoan' size='12' readonly></td>";
    	$b.="		</tr>";
    	$b.="		<tr>";
    	$b.="			<td colspan='2'><hr></td>";
    	$b.="		</tr>";
    	$b.="		<tr>";
    	$b.="			<td colspan='2'><input type='button' value='Calculate' onClick='calcATable();'></td>";
    	$b.="		</tr>";
    	$b.="	</table><br>";
    	$b.="	<div id='amortTable'></div>";
    	echo $b;
    When I try to open the file, it get a T_STRING error. Please help. What must be the problem with my codes? And can you please help me in revising the codes to make it work well in php?

    Thank you in advance!
    Big things come in small packages

  2. #2
    Join Date
    Mar 2010
    You asked exactly the same question over at codingforums in your thread there. You were given the answer there. What don't you like about it.

  3. #3
    Join Date
    Jan 2011
    Yes, I did. Sorry, I saw the reply a few minutes after posting here. And the question I asked there was not as detailed as I did here.

    However, I was just hoping I could get several answers so I could at least learn various ways of solving the problem I'm encountering.

    If this caused any trouble, I deeply apologize.
    Big things come in small packages

  4. #4
    Join Date
    Mar 2010
    The solution you were given at codingforums is much better than what you are trying to do now by joining together each line of code in a php string and then echoing it.

    All you have to is, as suggested in the other forum, is to give your filename a .php extension and that will tell the web server to treat your page as a php file and so pass it through the php parser and processor on the server before sending the html back to the browser.

  5. #5
    Join Date
    Mar 2010
    you have syntax errors (missing and unmatched quotes) in the php code.

  6. #6
    Join Date
    Aug 2004
    I see no obvious reason to assign all that text to a PHP variable and then echo that variable. Unless you actually need to manipulate the text in some way, just remove all the PHP stuff, as it appears to be serving no purpose (except maybe eating up a millisecond or two of processing time). If you ever do have a reason to assign a bunch of straight HTML text like that to a PHP variable, you'll likely find that the heredoc syntax will save you a lot of grief.

    Both of these do the exact same thing:

    <p>This is a test.</p>
    PHP Code:
    <p>This is a test.</p>
    So why not use the "example1.php" version if you don't need to do anything else?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09941 seconds
  • Memory Usage 2,917KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates