Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

variable variables for tablename

Posted on 2013-06-26
5
Medium Priority
?
168 Views
Last Modified: 2013-06-27
want to make the mysql table dynamic

$used_table='search';

change
$search_id=$rowcheck->search_id;

to
$${$used_table.'_id')}=$rowcheck->$used_table.'_id';
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39279096
Try:

$i = "_id";
$used_table[$i] = $rowcheck->$used_table[$i];
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39279227
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.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39279872
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.
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 39280801
$used_table='search';
${$used_table.'_id'}=$rowcheck->{$used_table.'_id'};
echo $search_id;//should give you the value that was stored in $rowcheck->search_id

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 39283406
Yes, I should use another design pattern.
But this example works the best

Thanks
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question