|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Hi,
I have just created the editor thanks to the great articles on this website... and it all works fine... I have done the code to let me save the text to the DB no problem... but I want to get the text from the DB and load it in to the iFrame window.... I have looked through this forum and managed to get some text in, but not the DB text..... I have the following code: ------------------------------------------------- var src = ' hello '; function Init() { iView.document.designMode = 'On'; iframeWin = window.frames.iView; iframeWin.document.open(); iframeWin.document.write(src); iframeWin.document.close(); } --------------------------------------------------- That manages to put "hello" in to the editor window, but when I tried: var src = '<? echo "$text"; ?>'; it comes up with loads of errors.... I have one main page called "admin.htm" which has hyperlinks to "editpage.php" and a variable is passed over "?pageid=1" which then is used to select the record from the DB. this is then supposed to be read in as $text value so it can be edited. Plllleaaasse help!! Thanks! Matt F Manchester, UK. |
|
#2
|
|||
|
|||
|
ahh, matt, this has been the most popular topic on this forum 2 date, eheh, what you have to do is much simpler then you think
firstly create a php page (call it: load.php) in this page you need to print out the data you want to be able to edit in they wysiwyg editor. PHP Code:
|
|
#3
|
|||
|
|||
|
WOOO HOO HOO HOOOOOOO!!
It works!! Thanks V MUCH!!!! Matt |
|
#4
|
|||
|
|||
|
Good work Ben,
But just about your earlier problem: var src = ' hello '; function Init() { iView.document.designMode = 'On'; iframeWin = window.frames.iView; iframeWin.document.open(); iframeWin.document.write(src); iframeWin.document.close(); } The reason you would've got errors is because if you loaded text into the src attribute, it would've had quotes and new lines. you just have to replace ' with \' and a new line with \r\n so that the string sits on one line and it would all work fine. Bens method is easier tho :P |
|
#5
|
|||
|
|||
|
Thanks for all the help on this one!
Ben's idea worked perfectly, but you were right with the new line thingy... it was when the value was being returned from the DB that it was adding new lines to the text string which send the javascript crayzee! I'm just working on the image upload now! ;-) Cheers!! |
|
#6
|
|||
|
|||
|
I had a request for my code for the solution to my earlier problem:
getting the record from the DB in to the editor window... here is my code and how I did it: -------------------------------- In your Editor Page ... ... -------------------------------- Firstly (as mentioned above by Ben) you need to find the section which relates to the <iFrame>.. this is the actual editing part of the editor and the place where the text from the DB will be imported. You need to specify a source for the iFrame. This source will be a seperate page which gets the data from the DB... then it is loaded in to the <iFrame> section... so... add this (or similar) line to the <iFrame> tag... <iframe id="iView" style="width: 600px; height:400px" src="load.php?id=<?= $id ?>"></iframe> The important part it the src="load.php" part... This is the page which we will create next. When the editor loads, it goes away and gets the page "load.php".... this is shown next: -------------------------------- Create a new Page called load.php and insert the following code: -------------------------------- <?php global $id; mysql_connect("localhost","username","password"); mysql_select_db("database_name"); $query = mysql_query("SELECT * FROM table_name WHERE id=$id"); while($row = mysql_fetch_array($query)) { $text = $row['DB_field_with_text_you_want_to_return']; echo "$text"; } ?> this page opens the DB and finds the record which the <iFrame> has specified. As you can see in the <iFrame src="load.php?id=<?= $id ?> there is a variable called $ID. This is called when you first load the editor page. so.... when you load the editor page, you will need to tell it which record you want to display in the iFrame part... so the URL might be: editor.php?id=1 this will populate the iFrame src part and will look like: <iframe id="iView" style="width: 600px; height:400px" src="load.php?id=1"></iframe> then the load.php file will get the variable $id and open the DB and find the record with ID = 1... then that page will return the text from the DB in to the iFrame window... I hope this is clear??!!! I have tried to explain it as smply as possible?!! Let me know if you need anymore help.... Maybe there could be a 3rd part to the WYSIWYG articles on this site...as this appears to be a popular question?!! Regards, |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > PHP WYSIWYG getting frame source from DB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|