Forum Moderators: coopster

Message Too Old, No Replies

displaying database contents within something.

         

surrealillusions

8:27 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



I am trying to setup a cms system. However, i want to display the current content in the textarea where the user can edit the text, so they dont have to type it all out again. This is the bit where it sets the value for the text already in there. But this just echos the code within the '. I've tried all sorts of combinations with " and such..but this is the closest i've got to it. The database user/pass and such are already set on the page. I've ran out of ideas on what to do.

$variablename->Value = '

$data = mysql_query ("SELECT * FROM dbtable ORDER BY id DESC")
or die (mysql_error());

$info = mysql_fetch_array ( $data );
{
echo "" .$info[\'FCKeditor1\'] . "";
}

';

:)

PHP_Chimp

9:02 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$data = mysql_query ("SELECT * FROM dbtable ORDER BY id DESC")
or die (mysql_error());
$info = mysql_fetch_array ($data);
$variablename->Value = $info['FCKeditor1'];

How about this?

surrealillusions

9:58 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Thanks, that did the trick.

Can you explain what you did please?

:)

PHP_Chimp

10:14 am on Jan 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$data = mysql_query ("SELECT * FROM dbtable ORDER BY id DESC")
or die (mysql_error());
$info = mysql_fetch_array ($data);

All of the above is from your original code, so no need to explain that.

With your original -


$variablename->Value = ' // start of variable
// get info from database, removed to save space
$info = mysql_fetch_array ( $data );
{ // start of statement-group...but no conditions attached to this
echo "" .$info[\'FCKeditor1\'] . ""; // echo " ' would break you out of the variable, as you are using ' to group everything
} // end of statement-group
'; // end of variable

The manual has a bit about the control structures [uk3.php.net]. So you can see about the {}'s.

You are trying to run all of your get info/fetch array within your variable. You are sort of trying to run a function within a variables, like you can do within javascript. You can do a similar thing with php using create_function [uk2.php.net].

However as you are trying to get a known array value into your $variablename->Value it would be a lot easier to read if you just use one = other.

So get all of your information. Then -


$variablename->Value = $info['FCKeditor1'];

[edited by: PHP_Chimp at 10:19 am (utc) on Jan. 30, 2008]