ab1233 Posted April 8, 2009 Share Posted April 8, 2009 I am attempting to select the contents of an entire table, select the "name" cell from each row, and create a variable displaying that row's "content" cell. This is for a low-end content management system I'm developing. The file, language.php, gets called in with the header and from there generates all the text snippets needed throughout the site, so that they can be edited by an admin online instead of having to do any work directly in the coding. Essentially, what I have (and am failing with) is this... $sql_textareas = "SELECT * FROM textareas"; $result_ta = mysql_query($sql_textareas); $results_ta = mysql_numrows($result_ta); while($textarea = mysql_fetch_array($result_ta)) { $child = $textarea['name']; ${"texarea_".$child} = $textarea['content']; } The goal would be able to have $child equal something like welcome and then have $textarea_welcome's content be displayed anywhere on the website (when the file is called and whatnot). By enacting the while statement I was hoping that a variable could be made for each row in the able, but right now nothing has been functioning as I had hoped. Is is possible to basically make a variable out of another one? Quote Link to comment https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/ Share on other sites More sharing options...
ram4nd Posted April 8, 2009 Share Posted April 8, 2009 $sql_textareas = "SELECT * FROM textareas"; $result_ta = mysql_query($sql_textareas); $results_ta = mysql_numrows($result_ta); while($textarea = mysql_fetch_assoc($result_ta)) { $child = $textarea['name']; $texarea_child = $textarea['content']; } Quote Link to comment https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/#findComment-804228 Share on other sites More sharing options...
ab1233 Posted April 8, 2009 Author Share Posted April 8, 2009 Thank you for the quick response... but this didn't seem to do the trick. :/ Is it OK that $textarea_child wasn't something along the lines of what $textarea_$child might imply? Quote Link to comment https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/#findComment-804249 Share on other sites More sharing options...
ab1233 Posted April 8, 2009 Author Share Posted April 8, 2009 Additionally (and partly for a bump of this thread), how would using mysql_fetch_array be any different from mysql_fetch_assoc? Quote Link to comment https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/#findComment-804539 Share on other sites More sharing options...
ram4nd Posted April 8, 2009 Share Posted April 8, 2009 you cant make variable name like you make strings, variable vant include $ and cant start with number. mysql_fetch_array - can use names and numbers to get values, assoc is names only, since you use names why not to use assoc But i still dont get that what yo want to do, contact me via msn or aim and i help you Quote Link to comment https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/#findComment-804626 Share on other sites More sharing options...
sasa Posted April 8, 2009 Share Posted April 8, 2009 $sql_textareas = "SELECT * FROM textareas"; $result_ta = mysql_query($sql_textareas); $results_ta = mysql_numrows($result_ta); while($textarea = mysql_fetch_assoc($result_ta)) { $child = 'texarea_' . $textarea['name']; $$child = $textarea['content']; } Quote Link to comment https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/#findComment-804635 Share on other sites More sharing options...
ab1233 Posted April 9, 2009 Author Share Posted April 9, 2009 At first thought, this concept seemed really easy. It's turning into a bit of a monster instead. I basically need to be able to get the content of a textarea (or a snippet... not an actual <textarea></textarea> from the database to the page when it's called somewhere in the code, with the hope that I could just echo "$textarea_whatever"; and have that text show up there. It's a concept similar to the one behind a content management system, I suppose, I just at this point seem a bit lost in how this can be done. Additionally, I realize that there are probably more efficient ways to call the data, but I figured that calling the MySQL data once per page would be easier than having to repetitively use the SELECT xx WHERE name="" function. Doing the later would remove the need for what I'm doing, but I just don't see how it's efficient. Any ideas would be awesome, but at this point I may be over my head trying to explain what the goal is. Quote Link to comment https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/#findComment-805113 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.