Return to iWEBTOOL

Go Back   iWEBTOOL Talk > The Web and your Website > Programming > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
Welcome to iWEBTOOL Talk, where you talk about webmaster-related stuff.
 
Discuss topics which interest you.
With over thousands of threads (topics), we're sure you'll find something that'll interest you.
Ask for help whenever you need it.
We have thousands of members who are available to help you if you need it.
It's absolutely FREE!

 1  Register           2  Browse the board           3  Discuss whatever may interest you!
 


Reply
 
Thread Tools Search this Thread Display Modes
Old 03-04-2008, 11:50 AM   #1
jiri
Smurf
 
jiri's Avatar
 
Join Date: Mar 2008
Posts: 1
jiri is on a distinguished road
Talking SELECT * FROM TABLE where table name is variable

Hi everyone,

I run w/o problem:

$query = 'SELECT * FROM customers_table WHERE customer_id=\''.$customer_id.'\' ';

I need to replace the tablename called "customers_table" above with a variable, e.g.

$table = 'customers_table';
$query = 'SELECT * FROM $table WHERE customer_id=\''.$customer_id.'\' ';

It report's error.

I have tried also this way:

define("CUSTOMERS_TABLE", "customers_table");

$query = 'SELECT * FROM CUSTOMERS_TABLE WHERE customer_id=\''.$customer_id.'\' ';

It report's error, but if I write CUSTOMERS_TABLE in lowercase, all is OK.

The purpose is to have more entries into program and onetime I use
define("CUSTOMERS_TABLE", "customers_table");

nextime will be

define("CUSTOMERS_TABLE", "peters_table");

and next time

define("CUSTOMERS_TABLE", "alices_table");

and so far...

Can you help how to write $query = ... correctly?
jiri is offline   Reply With Quote
 
This is an Ad Revenue Sharing forum Place your advert here
SEO Checklist
Get yourself better ranking with
our "Do-it-Yourself" SEO Checklist.
Click Here
Old 03-12-2008, 08:59 PM   #2
Intripita-MH
Senior Member
 
Intripita-MH's Avatar
 
Join Date: Sep 2006
Posts: 292
Intripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to behold
Send a message via AIM to Intripita-MH Send a message via MSN to Intripita-MH Send a message via Yahoo to Intripita-MH
Default Re: SELECT * FROM TABLE where table name is variable

Code:
$query = "SELECT * FROM " . $table . " WHERE customer_id='$customer_id'";

Try that.
__________________
Intripita :: web hosting | development | conferencing

Business-Grade Web Hosting, Professional Conferencing, Effective Web Development by Intripita
Intripita-MH is offline   Reply With Quote
 
This is an Ad Revenue Sharing forum Place your advert here
Webmaster Tools Webmaster Tools Click Here
Reply



Quick Reply
Message:

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
table not expanding wwe9112 HTML 2 02-23-2008 12:30 PM
Changing multiple Table entries? marcusa007 PHP 2 05-06-2007 10:07 PM
What do you think how Google PR DB table looks like? 123_free_links Google 10 04-30-2007 03:52 PM
Table within a table jumpenjuhosaphat PHP 5 08-05-2006 11:20 PM
New table builder web tool 3w.ezer.com 123_free_links Website Reviews 4 06-26-2006 11:26 AM


All times are GMT. The time now is 08:07 AM.


Powered by vBulletin v3.6.7 © 2008, Jelsoft Enterprises Ltd. SEO by vBSEO © 2006, Crawlability, Inc.