Solved

variable variables for tablename

Posted on 2013-06-26
5
157 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 6

Expert Comment

by:Robert Saylor
ID: 39279096
Try:

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

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 108

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 500 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now