Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

variable variables for tablename

Posted on 2013-06-26
5
Medium Priority
?
169 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
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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …
Suggested Courses

885 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