my html fragment is floating to the top of my page!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

my html fragment is floating to the top of my page!

Post by kc11 »

Hello everyone,

I am working with codeigniter .2.1 and twitter bootstrap to develop a site. I used php's domdocument to generate some dynamic html which I want to insert into a page.Unfortunately , the php generated fragment is now the first thing on the page when I look at the html source:

Code: Select all

<div><h2>Available Now:</h2></div>
mod: 1mod: 2<div class="row"><div class="span6"><h2>13 mole st</h2><p>Fugazi</p><p><a class="btn" href="http://localhost/bootstrap1/index.php/template_controller/1">Learn More &raquo;</a></p></div><div class="span6"><h2>11 mole st</h2><p>Fugazi</p><p><a class="btn" href="http://localhost/bootstrap1/index.php/template_controller/2">Learn More &raquo;</a></p></div></div>

---------generated fragment is above

<!DOCTYPE html>
<html lang="en"><head>

I actually want to insert this further down the page. What am I doing wrong?

Thanks,

KC
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: my html fragment is floating to the top of my page!

Post by social_experiment »

What is above the doctype declaration on the page where you created the code
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

Re: my html fragment is floating to the top of my page!

Post by kc11 »

Here is the code:

Code: Select all

 $dom = new DOMDocument('1.0'); //Create new document with specified version number
          $div= $dom->createElement('div') ;  
             $dom->appendChild($div);   
             $h3=$dom->createElement('h2','Available Now:');
             $div->appendChild($h3); 
             echo $dom->saveHTML();
So, if I understand correctly, this means we are using xml version="1.0".

Thank you for looking at it,

Bill
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: my html fragment is floating to the top of my page!

Post by social_experiment »

Code: Select all

<?php
   echo $dom->saveHTML();
?>
If you comment the above line, does the content disappear?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

Re: my html fragment is floating to the top of my page!

Post by kc11 »

Yes,

Please note that I have another section of code (which I did not include above) that produces a second fragment of html which is included in the original html fragment I showed in my first post. it also starts with:

Code: Select all

$dom = new DOMDocument('1.0');
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: my html fragment is floating to the top of my page!

Post by social_experiment »

Code: Select all

<?php
 $dom = new DOMDocument('1.0'); //Create new document with specified version number
          $div= $dom->createElement('div') ;  
             $dom->appendChild($div);   
             $h3=$dom->createElement('h2','Available Now:');
             $div->appendChild($h3); 
             echo $dom->saveHTML(); 
?>
Is there a specific reason why you have this above the doctype declaration
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

Re: my html fragment is floating to the top of my page!

Post by kc11 »

Its not above the doctype declaration, I want the area of generated HTML to be lower.

To build this page my codeigniter controller looks like:

Code: Select all


public function index()
	{
		
		
		$this->load->view('header'); // static HTML including doctype declaration
		$this->load->view('navbar'); // static HTML
		$this->load->view('hero_unit'); // static HTML
                
                $this->currentItems();  // my generated HTML ( which we are discussing )
              
		$this->load->view('footer'); // static HTML
			
		
	}
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: my html fragment is floating to the top of my page!

Post by social_experiment »

Ok; well my knowledge of both DOMDocument and codeIgniter are non-existant so an alternative i can offer is to refer you to a tutorial on the codeIgniter site; Hth
http://codeigniter.com/user_guide/tutor ... pages.html
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

Re: my html fragment is floating to the top of my page!

Post by kc11 »

Thanks for looking at it,

KC
Post Reply