Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

variable variables for tablename

want to make the mysql table dynamic

$used_table='search';

change
$search_id=$rowcheck->search_id;

to
$${$used_table.'_id')}=$rowcheck->$used_table.'_id';
Avatar of Robert Saylor
Robert Saylor
Flag of United States of America image

Try:

$i = "_id";
$used_table[$i] = $rowcheck->$used_table[$i];
Avatar of gr8gonzo
Do this:
$used_table = "search";
$used_table_id = $used_table."_id";
$$used_table_id = $rowcheck->$used_table_id;

That will create the same result as:
$search_id = $rowcheck->search_id;

You might also consider using the extract() function.
Please show us the $rowcheck object.  I smell something fishy in this design pattern and I think if we knew a little more about what you're working toward we could suggest a design pattern that would be more secure and less brittle than what I sense may be going on here.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

Yes, I should use another design pattern.
But this example works the best

Thanks