Solved

variable variables for tablename

Posted on 2013-06-26
5
163 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 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 109

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

773 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