Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/153104-intricate-variable-manipulation/
Share on other sites

$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'];
     }

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

$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'];
     }

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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