pcbytes Posted March 20, 2007 Share Posted March 20, 2007 OK I have populated a database with information. On my site I pull a thumbnail picture in the database and the print CSS code in a text area that is associated with that picture. Now my question is this. Lets say my database contains the following text information. <style type="text/css"> body { background-color: $color; } </style> Then I pull in that CSS code to my textarea and display it to the screen with the code below... Problem is the output shows: <style type="text/css"> body { background-color: $color; } </style> Is there a way I can pull that data from my database and have the $color variable filled? Below is my code as it is right now it works with the exception of I have have no idea how to change the value $color in the text pulled in by $codes....... BASICALLY in a nutshell, I want my CSS code that is shown in the textarea box to be dynamic along with the entry I am displaying. index.php <!-- FORM TO DISPLAY DATABASE TEMPLATES --> <form name="form1" method="post" action="<?php echo $PHP_SELF?>"> <select name="section" size="1" multiple> <option selected>layouts</option> </select> <select name="category" size="1"> <option selected>animals</option> <option>Anime</option> </select> <br> <input type="submit" name="Submit" value="Submit"> </form> <? //GET FORM DATA $section = $_POST['section']; $category = $_POST['category']; //CONNECT TO DB mysql_connect("localhost","jason","password"); mysql_select_db("test"); //GET DATABASE RESULTS BASED ON CATEGORY PICKED $result = mysql_query("select * from upload where category = '$category'"); //FETCH SQL DATA AND PRINT IT TO THE SCREEN while($row = mysql_fetch_array($result)){ $id = $row["id"]; $codes = $row["codes"]; print '<table width="400" border="2" cellspacing="0" cellpadding="0">'; //DISPLAY THUMBNAIL IMAGE FROM DATABASE print ("<tr><td><img src=\"download.php?id=$id\"></td></tr>"); //POPULATE TEXTFIELD WITH CSS CODE FOR TEMPLATE print "<tr><td><textarea name='textfield' wrap='OFF' cols='50' rows='7'>".$codes."</textarea><td></tr>"; print '</table><br /><br />'; } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/43459-solved-is-there-a-way-to-do-this-change-value-from-imported-text/ Share on other sites More sharing options...
pcbytes Posted March 20, 2007 Author Share Posted March 20, 2007 perhaps it would be possible to ereg_replace() on variable $code and scan the string for the $color statement and replace it with the value of $color. Link to comment https://forums.phpfreaks.com/topic/43459-solved-is-there-a-way-to-do-this-change-value-from-imported-text/#findComment-211079 Share on other sites More sharing options...
pcbytes Posted March 20, 2007 Author Share Posted March 20, 2007 alrrrrighty well that works on regular text.. but I cant get it to replace the $ sign in the text I've tryed: $codes = ereg_replace("\$color", "replacement text", $codes); is my syntax correct? Link to comment https://forums.phpfreaks.com/topic/43459-solved-is-there-a-way-to-do-this-change-value-from-imported-text/#findComment-211095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.