0

I'm trying to pass a php variable name to mysql and then retrieve the variable name back where it displays the appropriate value.

UPDATE: APOLOGIES: As each page will have a different VARIABLEVALUE as called by MySql. ::UPDATE ENDED::

Currently I'm using mysqli, with varchar, but should I be using text? or is this irrelevant.

Data stored in contentData on mysql is as such:

$variableName = VARIABLEVALUE;

So SQL dataRow is:

Some data and information $variableName some data and information

php code i am trying to use to retieve the text and variable is:

$variable = $row_mysqlresult['contentData'];

I'm calling the data as above, but also re-indexing to:

$variable = '. $variable .';
echo = $variable ;

This now displays

Some data and information $variableName some data and information

Instead of

Some data and information VARIABLEVALUE some data and information

I think I've just overcomplicated what I'm trying to do...

Any help, much appreciated :))

5
  • If I understand correctly, you just have a concatenation or interpolation problem? 3v4l.org/Jjg5Z Commented Jul 9, 2024 at 18:37
  • Sorry, I do not understand. Please give an example of what you want to put in and what you want get back. Btw. echo = $variable ; is no valid syntax. Commented Jul 9, 2024 at 19:23
  • The difference between TEXT and VARCHAR is irrelevant to PHP. It mainly affects the storage efficiency in the DB. Commented Jul 9, 2024 at 19:56
  • When you pass a variable to a function, the function receives the variable's value, it can't get the variable name. If names are significant, you probably should be using an associative array, not separate variables. Commented Jul 9, 2024 at 19:56
  • $variable = '. $variable .'; just makes a string whose contents are " $variable " (i.e a space, a $, the word "variable" and another space). Variable names in single-quoted strings in PHP aren't transformed into the variable value. If you want to add spaces either side of the string you need double-quotes here. I'm also guessing the .s aren't really what you wanted? So try: $variable = " $variable "; Commented Jul 9, 2024 at 19:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.