Jump to content

Storing text with variables to be called when text is used in a DB - issues


ctrenks

Recommended Posts

I am storing text in a blob in SQL, then generating the variable values in code then bringing up the text, the text however shows blank where the variable are although en echo after the text display will show the var displayed correctly.

 

heres an example.

 

Stored text : This is a test to show the variable <? echo $variable ?>, if this works it should be displayed as below.

 

I set $variable="test";

 

echo the stored text and i get

 

This is a test to show the variable , if this works it should be displayed as below.

 

when I want to see

 

This is a test to show the variable test, if this works it should be displayed as below.

 

TY!

Not sure if I am the only one, but I am having a really hard time understanding what it is you are trying to do.

 

???

 

<?php

$q = mysql_query("SELECT * FROM test") 

while($row = mysql_fetch_array( $q )) {

$var = $row["mysql_table_row"]

echo $var;

}

?>

This seems so simple its confusing!

 

I am storing text in a db, and in that stored text I want to call a variable, so in the text I added <? echo $var ?> so if the variable needs to change i can change it without changing all the stored text. 

 

So, I want to display the text on a web page with the current variable data in the spot, not that this is practicle but lets use a date as an example.

 

I store this into the db :

 

Todays date is <? Echo $date_var ?>

on my page i want to display it I do this

 

$date_var = $today;

$disp_text = "Todays date is <? Echo $date_var ?>";

echo $dsp_text;

 

hoping to get:

Todays date is 03/30/2007

Easiest way is to store "placholder" text in the db text

 

eg

<?php
$db_text = 'My name is #NAME#. Todays date is #DATE#';

$search = array ('#NAME#', '#DATE#');
$replace = array('ctrenks', date('m/d/Y'));

echo str_replace($search, $replace, $db_text);     //--> My name is ctrenks. Todays date is 04/01/2007
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.