[PHP] Variables in Variables?
Greetings. Does anyone know how to do this? I have, $var $var2 In a field called two_vars in a MySQL db. I am calling the variables inside PHP document. In that document I am saying: $var = time $var2 = clock !-- I do the query in MySQL here -- echo $two_vars; But the what prints out is $var $var2 not time and clock. I know that is what is in the database, but I want it to replace the variables when printed in the PHP file. Does this make sense to anyone? Does anyone know how to do this? -- Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variables in variables?
This is a little more specific: I have a template in the database which looks something like this: html title$page_title/title body Image: $image p / img src = \$image\ Main Text: $mtext br / Text2: $text2 br / Text3: $text3 br / /body html The variable name is $somecontent When I call $somecontent in the PHP file, it displays exactly like it is above. It does not replace the variables. Is there a reason for this? Here is my PHP file: ?php include cnx.php; include includes/header.php; //Include the content $select_data = SELECT * FROM template WHERE tmpl_name = \my_template\;; $response = mysql_query( $select_data, $cnx ); //now print it out for the user. if ( $one_line_of_data = mysql_fetch_array( $response ) ) { extract ( $one_line_of_data ); } $file = $_POST['file']; $page_title = $_POST['page_title']; $image = $_POST['image']; $mtext = $_POST['mtext']; $text2 = $_POST['text2']; $text3 = $_POST['text3']; if (file_exists($dir . $file)) { echo centerp /p class=\NormalBold\Success!p /p /; } else { echo The file $file does not exist; } $filename = $file; //Update the table in MySQL $update_data = UPDATE cms_pages SET page_title = '$page_title', image = '$image', mtext = '$mtext', text2 = '$text2', text3 = '$text2' WHERE filename = '$file'; $response = mysql_query( $update_data, $cnx ); if(mysql_error()) die ('database errorbr'. mysql_error()); //Begining of Template Construction $mtext = nl2br($mtext); $text2 = nl2br($text2); $text3 = nl2br($text3); //include content.php; This works with an external page included, but I would like it to be in the database for easy changes. // Is the file writable? if (is_writable($dir. $filename)) { if (!$handle = fopen($dir . $filename, 'w')) { echo Cannot open file ($filename); exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo Cannot write to file ($filename); exit; } echo centerp /p class=\NormalText\$filename has been updated./pp //center; fclose($handle); } else { echo The file $filename is not writable; } include includes/footer.php; ? /html on 11/18/05 7:14 PM Lists ([EMAIL PROTECTED]) wrote: ? $var = time; $var2 = clock; echo $var$var2; //outputs timeclock $two_vars = $var$var2; echo $two_vars; //outputs timeclock ? Why put two variables in one field? But if you want to store them, do: $var, $var2. After pulling this back from the database, explode into an array at the comma, using list to call them var and var2. On Nov 18, 2005, at 7:54 PM, Marquez Design wrote: Greetings. Does anyone know how to do this? I have, $var $var2 In a field called two_vars in a MySQL db. I am calling the variables inside PHP document. In that document I am saying: $var = time $var2 = clock !-- I do the query in MySQL here -- echo $two_vars; But the what prints out is $var $var2 not time and clock. I know that is what is in the database, but I want it to replace the variables when printed in the PHP file. Does this make sense to anyone? Does anyone know how to do this? -- Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] variables within variables - question
Im having a VERY hard time trying to explain this Here is a bit of my code... for ($i = 0; $i $num_fields; $i++) { $field = mysql_field_name($result, $i); $field2 = .$field; $output = str_replace($field2, $field), $output); } The problem I'm having here is that the variable $field contains a string (a name of one of my fields in my table). I need for the variable $field to actually point to the another variable, not just contain the string. This little loop here is supposed to go through a RTF file and replace all the $field2 it finds with $field. Am I making sense? THANKS!!!
RE: [PHP] variables within variables - question
$field2 = .$$field; -Original Message- From: Phil Schwarzmann [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 27, 2002 12:33 PM To: [EMAIL PROTECTED] Subject: [PHP] variables within variables - question Im having a VERY hard time trying to explain this Here is a bit of my code... for ($i = 0; $i $num_fields; $i++) { $field = mysql_field_name($result, $i); $field2 = .$field; $output = str_replace($field2, $field), $output); } The problem I'm having here is that the variable $field contains a string (a name of one of my fields in my table). I need for the variable $field to actually point to the another variable, not just contain the string. This little loop here is supposed to go through a RTF file and replace all the $field2 it finds with $field. Am I making sense? THANKS!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variables within variables
On Sat, Apr 28, 2001 at 07:12:15PM +0100, Robert Morrissey wrote: I have a form on one page with a text box called 'emailtext'. This gets passed to a php script that gets info from a database (such as $name, $email, etc) and mails selected email addresses; my problem is this: Say, the form passes $emailtext as Hello $name, how're you?, and this is passed to mail() in the php form, rather than emailing Hello Bob, how're you? it prints $name literally. Seeing as $name isn't pulled from the database till the php script is it possible to get it to print the value? or do I have to pull $name from the database in the original form? (which'll is going to be a lot more complicated). Does this make sense? No, not really. What is the value of $name when the form passes $emailtext? That is the value that will be in $name. If it is actually printing $name and not an empty string, then the '$' must be getting escaped somewhere along the line, or you are using ' instead of around the variable. http://www.php.net/manual/en/function.echo.php -- Jason Stechschulte [EMAIL PROTECTED] -- I'll say it again for the logic impaired. -- Larry Wall -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] variables within variables
Hi, I have a form on one page with a text box called 'emailtext'. This gets passed to a php script that gets info from a database (such as $name, $email, etc) and mails selected email addresses; my problem is this: Say, the form passes $emailtext as Hello $name, how're you?, and this is passed to mail() in the php form, rather than emailing Hello Bob, how're you? it prints $name literally. Seeing as $name isn't pulled from the database till the php script is it possible to get it to print the value? or do I have to pull $name from the database in the original form? (which'll is going to be a lot more complicated). Does this make sense? Thanks for any help, Robert Morrissey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]