displaying PHP in innerHTML

Discussion in 'PHP' started by ashrafzia, May 17, 2008.

  1. #1
    I have CSS Tabs.
    I want to display php code in innerHTML.

    my code is:

    if (tab=="admin"){
    main.innerHTML="<center><strong>Admin Details</strong></center>
    <?php 
                $sql = "select * from payments where client_id = $_POST[c_id]";
                print $sql;
                $res = mysql_query($sql);
                $row = mysql_fetch_assoc($res);
                $b_name = $row['bank_name'];
                echo "$b_name";
            ?>
                
            ";
        }
    Code (markup):
    The php code isn't dispalying.
    please Help
     
    ashrafzia, May 17, 2008 IP
  2. allaboutgeo

    allaboutgeo Peon

    Messages:
    85
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    allaboutgeo, May 17, 2008 IP
  3. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #3
    What is 'main' in your code.

    if its a id of some HTML element, you shoud do this:

    document.getElementById('main').innerHTML = '<?php
    whatever.....
    ?>
     
    samyak, May 19, 2008 IP
  4. ashrafzia

    ashrafzia Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here's my full code :

    
    elseif (isset($_POST['proceed'])) { 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>::: client Invoices :::</title>
    
    <style>
    .admin, .client, .servicesete { background-color:#CCFFFF; border:1px solid #0000FF; display:inline; padding:3px 5px 0.5px 5px;
    									}
    .admin { background-color:#FFFFFF; border-bottom-color:#FFFFFF;}
    .main { border:1px solid #0000FF; height:300px; width:717px; margin-left:145px; }
    
    .admin a, .client a, .servicesete a { text-decoration:none; color:#000000; font-family:Geneva, Arial, Helvetica, sans-serif; }
    
    </style>
    
    <script>
    function changeTab(tab) {
    	var currentPage = document.getElementById(tab);
    	var admin = document.getElementById('admin');
    	var client = document.getElementById('client');
    	var services = document.getElementById('services');
    	var main = document.getElementById('main');
    
    admin.className = "client";
    client.className = "client";
    services.className = "client";
    
    
    currentPage.className = "admin";	 
    
    	if (tab=="admin"){
    		main.innerHTML="<center><strong>Admin Details</strong></center>
    		<?php 
    			$sql = "select * from payments where client_id = $_POST[c_id]";
    			print $sql;
    			$res = mysql_query($sql);
    			$row = mysql_fetch_assoc($res);
    			$b_name = $row['bank_name'];
    			echo "$b_name";
    		?>
    			
    		";
    	}
    	else if (tab=="client"){
    		main.innerHTML="<center><strong>client Record</strong></center>";
    	}
    	else if (tab=="services"){
    		main.innerHTML="<center><strong>servicesete Record</strong></center>";
    	}
    	
    }
    </script>
    </head>
    
    <body>
    
    <div style="margin-top:70px;">
    	
    		<div id="admin" class="admin" style="margin-top:100px; margin-left:150px;" onMouseOver="changeTab('admin')">
    		<a href="javascript:;">Admin Details</a></div>
    		<div id="client" class="client"  onMouseOver="changeTab('client')">
    		<a href="javascript:;">Client Details</a></div>
    		<div id="services" class="servicesete" onMouseOver="changeTab('services')">
    		<a href="javascript:;">Services Availed</a></div>
    		
    	
    </div>
    <div id="main" class="main"></div>
    
    
    <?php }
    echo "<br>";
    show_footer();
    ?>
    </body>
    </html>
    
    PHP:
     
    ashrafzia, May 19, 2008 IP
  5. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #5
    DId you try
    document.getElementById(' main').innerHTML = ...

    instead of just main.innerHTML
     
    samyak, May 19, 2008 IP
  6. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #6
    If there is still a problem, upen this page in firefox.

    Then go to Tools/Error Console.

    It will show you the javascript errrors with the page. Take a screenshot and post it here. Debug will be much easier if we know the exact problem.
     
    samyak, May 19, 2008 IP