Jump to content

Store/Retrieve HTML code with Mysql


pacoblackxx

Recommended Posts

Hello guys,

 

I am a new programmer and i am building a new website. I would like to give me your advice for the following problem:

 

I want to build a webpage, in which there will be a <div id="book-content"> ...............</div> part. Inside this div i would like

to  dynamically display pages from a book. Each page will have text, scripting code blocks, blocks with the output of each scripting code, and images.

 

There will be a bar on the left of the webpage in which the user can select which page of the book he wants to load.

 

For example...My web page will look something like this...

 

 

<HTML>
  <HEAD> 
  </HEAD>

  <BODY>

    <DIV ID="PAGE-HEADER">
       //LOGO OF THE WEB PAGE
    </DIV>

    <DIV ID="PAGE-MENU">
      //PAGE MENU
    </DIV>
     
     <DIV ID="BOOK-INDEX"    WITH FLOAT:LEFT >
      //HERE A WILL SHOW THE CHAPTERS OF THE BOOK AND THE PAGES OF EACH CHAPTER
     </DIV>

     <DIV ID="BOOK-PAGE">
        //THE PAGE SELECTED FROM THE PREVIOUS 'BOOK-INDEX' MENU WILL BE DISPLAYED HERE WITH A MYSQL QUERY
        ******
     </DIV>

  </BODY>
</HTML>

Then in a mysql database, i would like to have records with a text field, that will contain for example the followng:

<h1> Chapter 1: bla bla </h1>

<p> in this chapter we will speak about bla bla bla.... </p>

<div id="code"> 

int main()
{
int x,y;
x=2;
y=3;
x=x+y;
}

</div>

<p> this will outpout the following:</p>

<div id="code output">
x=5!
</div>

 

 

I would like to get this html code from the database, and then show it in the <div id=BOOK-PAGE> div.

 

But i dont want to use php eval().

Also, if i store the code to a file and then include it, i will have too may files(equal to the book's number of pages etc 100).

 

 

Any ideas?

Link to comment
Share on other sites

your going to have to store it with something like htmlentities() and display it the same way. It will store this way:

< >

and if you call it out in your HTML for display like

< >

it will show the equivialant to it without actually processing it as HTML

the equivilant to < > is

< >

 

Link to comment
Share on other sites

thnx for te reply.

 

i would like the html code into the the database record to be processed!

 

No HTML TAGS will be visible into the  <DIV ID="BOOK-PAGE"> , except from the blocks of code .

 

think as i am building a website with php tutorials. I php tutorial will have say 100 pages, each page will have text with bla bla(In which any HTML tag i want to be prosseced, so i would like to be able to make new paragraphs with the <p> tag) , blocks of PHP/HTML/JAVASCRIPT code(etc with background color blue) witch i would NOT like to be processed, and images.

Link to comment
Share on other sites

What I meant was, if you have any HTML that your displaying on the page then your going to want to store it in a fashion like I mentioned it would work for the concept of if you hit the code key or the php key above this reply box it will store the code in a format that will be able to be displayed on the page without rending through the browser. However on the flip side of that if your looking to have a default template stored in a database then have other information pulled out of it then you can store it in a DB as is I would say LONGTEXT would be your best bet, however any double quotes and single quotes in the code being store you will have to break with a \ first so it doesnt break your php when your calling it out of the database.

 

Then in the case of the are you want to place what ever in the template you can put a unique string say something like [:myDBcontent:] and then str_replace that with the data you want to pull out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.