Solved

variable variables for tablename

Posted on 2013-06-26
5
166 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 110

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
e commerce steps shown instead of self testing 2 58
php mail() send emails but the message is lost 4 33
integrated two Separate file . 3 30
sitemap.xml 3 32
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

751 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