table include

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WayneG
Forum Newbie
Posts: 19
Joined: Thu Apr 02, 2009 6:53 am

table include

Post by WayneG »

Hi.
I want to use this text in an include file: "demo_2".
demo_2 is a table name in a database.
I want to call this table from a select statement from another file, i.e

Code: Select all

$result = mysql_query('SELECT * FROM include("../inc.LeagueNameLower1.php"); WHERE Match_No=1')
This obviously doesn't work, but is there a way of doing it?
Cheers.
Last edited by Benjamin on Tue Jun 23, 2009 10:33 am, edited 1 time in total.
Reason: Changed code type from text to php.
waseem83
Forum Commoner
Posts: 54
Joined: Tue Jun 23, 2009 3:51 am
Contact:

Re: table include

Post by waseem83 »

I hope there will be a solution for this. But i dont know any.
Last edited by onion2k on Tue Jun 23, 2009 4:01 am, edited 1 time in total.
Reason: If you post pointless crap again I'm going to ban you.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: table include

Post by onion2k »

Code: Select all

$table = file_get_contents("../inc.LeagueNameLower1.php");
$result = mysql_query("SELECT * FROM $table WHERE Match_No=1");
But.. why?! I can't think of a single reason why you'd want to do that.
WayneG
Forum Newbie
Posts: 19
Joined: Thu Apr 02, 2009 6:53 am

Re: table include

Post by WayneG »

Thanks.
Does it really matter why?
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: table include

Post by Eric! »

This is how an include works. Your inc.LeagueNameLower1.php file

Code: Select all

<? $table = "tablename"; ?>
Your main script

Code: Select all

include "../inc.LeagueNameLower1.php";
$result = mysql_query("SELECT * FROM $table WHERE Match_No=1");
I have no idea why in the world you would do this for a table.

EDIT why are my tags not working?
Last edited by Benjamin on Tue Jun 23, 2009 10:35 am, edited 1 time in total.
Reason: Fixed [code=php] tags.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: table include

Post by onion2k »

WayneG wrote:Does it really matter why?
Not really. It's just that you appear to be writing some really bad code. If you can explain why you're doing it we might well be able to offer some advice about how you can improve it.
WayneG
Forum Newbie
Posts: 19
Joined: Thu Apr 02, 2009 6:53 am

Re: table include

Post by WayneG »

Oh. Ok.
I am a novice at this, so I'm pretty sure its bad code!
The thing is, I try to keep it simple in such a way I can understand what I'm doing.
I'll try to explain:
I have a template directory which I use to copy to create other directories, each will have their own name/DB name etc. I have 132 folders (named 1-132), with identical files in. In 2 of the files I have a select statement. Instead of having to change the "select demo_1 ..." table in each file, I was thinking of having this statement in a separate file, so I would only have to change this file instead of everything in the 132 folders.
I realise this is still bad coding. Hope you can understand the waffle.
Wayne.
Post Reply