Crew-Portal Posted August 1, 2007 Share Posted August 1, 2007 Hi I have the mysql set up so members can sign up and then later when they want to they can make a clan! all the clans information is stored in multiple tables each containing what they want on the website and .css styles. Now all tables start with air_ (and then a 4 letter number that they chose). the problem is I cant seem to figure out how to get the mysql to call the table. This is the script. <?php $dbase = '$rt[iata']'; $query="select * from air_$dbase"; $rt=mysql_query($query); echo mysql_error(); ?> then the code gets called on whenever the user wants to display data <?php while($nt=mysql_fetch_array($rt)){ echo "Page info goes here. It gets called from the database"; ?> My problem is when I post $dbase = '$rt[iata']'; before the $rt=mysql_query($query); i get an erro stating that I have not gving the query a name and it cannot connect. When I post it after it says that the database cannot connect cause it does not contain that table. Just so you know the iata is the 4 digit code that idents the clan. for example if the $rt[iata] equals something like 1234 then its contents would get stored in the table air_1234 get it! If someone could Help I would just love it! (my database connection settings are in a required file that I left out of the script) Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/ Share on other sites More sharing options...
a1phanumeric Posted August 1, 2007 Share Posted August 1, 2007 Hi dude, Can you post the full MySQL error you get? It'd make it easier for me to diagnose the problem for you. Additionally, I wouldn't recommend creating a new table for each clan. Ed. Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313235 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 $dbase = '$rt[iata']'; Take a look at where the quotes are, you have 3, so 2 open, 1 close. That would make a problem Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313238 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 When Code like this <?php $dbase = '$rt[iata]'; $query="select * from air_$dbase"; $rt=mysql_query($query); echo mysql_error(); ?> I get 2 errors You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[iata]' at line 1 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\airlines.php on line 67 When Code Like this <?php $query="select * from air_$dbase"; $rt=mysql_query($query); $dbase = '$rt[iata]'; echo mysql_error(); ?> I Get 2 Errors Table 'virva.air_' doesn't exist Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\airlines.php on line 67 When Code Like This <?php $rt=mysql_query($query); $query="select * from air_$dbase"; $dbase = '$rt[iata]'; echo mysql_error(); ?> I Get 2 Errors Query was empty Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\airlines.php on line 67 Hope someone can help me out! Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313239 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 $dbase = '$rt[iata]'; $query="select * from air_$dbase"; $rt=mysql_query($query); Try: <?php $dbase = $rt['iata']; $query="select * from `air_".$dbase."`"; echo $query; $rt=mysql_query($query); ?> edited to put in php tags Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313242 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 <?php $dbase = $rt['iata']; $query="select * from `air_".$dbase."`"; echo $query; $rt=mysql_query($query); ?> Doesnt work get 2 errors select * from `air_` Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\airlines.php on line 67 Sorry but it dont work? ??? Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313245 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 My server is at 24.76.180.18:80 Just in case you want to see the errors Click Virtual Airlines > Demo Virtual Airlines. Then you should see error! Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313247 Share on other sites More sharing options...
a1phanumeric Posted August 1, 2007 Share Posted August 1, 2007 If you just echo out '$rt['iata']' do you get anything at all? Ed. Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313250 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 Echo out $dbase first, and if that doesn't work... <?php $dbase = $rt['iata']; echo $dbase; $query="select * from `air_".$dbase."`"; $rt=mysql_query($query); ?> ...it's looking like your variable rt['iata'] doesnt really exist. Are you sure it's not supposed to be $nt? Try this too: <?php $dbase = $nt['iata']; $query="select * from `air_".$dbase."`"; echo $query; $rt=mysql_query($query) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313251 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 You guys probably cant tell much from those few lines of code Here is the entire page. (I started making it about 5 minutes ago so most in Html lol) <?php $info = $_GET['info']; session_start(); $valid_user = $_SESSION['valid_user']; require_once("./require/config.php"); require_once("./require/get_config.php"); require_once("./require/functions.php"); require_once("require/setting.php"); include("./lang/default.inc.php"); $dbase = $rt['iata']; echo $dbase; $query="select * from `air_".$dbase."`"; $rt=mysql_query($query); ?> <head> <LINK REL="SHORTCUT ICON" HREF="favicon.ico"> <title>Home Page!</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body bgcolor="#64748B"> <center> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#26354A"> <td width="514" nowrap="nowrap"><p align="right" class="logo"><span class="tagline"> </span></td> <td width="1" height="70" nowrap="nowrap" class="logo"><p class="logo"> </td> <td width="250"> </td> </tr> </table> <table width="854" border="0"> <td width="763" class="NavTop"> </td> <td width="81" class="NavTop">Demo Build </td> </tr> </table> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#FF6600"> <td colspan="6"></td> </tr> <tr bgcolor="#D3DCE6"> <td colspan="6"></td> </tr> <tr bgcolor="#D3DCE6"> <td colspan="6"></td> </tr> <tr bgcolor="#FF6600"> <td colspan="6"></td> </tr> <tr bgcolor="#D3DCE6"> <td colspan="2" valign="top" bgcolor="#26354A"><p> <a href="index.php"> <-- Go Back!!!</a><p> <a href="&info=airlineinfo">Airline Information</a><br> <a href="&info=">Pilots / Ranks</a><br> <a href="&info=">Aircraft</a><br> <a href="&info=">Flights</a><br> <a href="&info=">Airbills</a><p> <a href="index.php"> <-- Go Back!!!</a> </td> <td width="5"></td> <td width="603" valign="top"> <?php if ($info == home){ while($nt=mysql_fetch_array($rt)){ echo "$nt[iata]"; } } else echo 'error'; ?> <td width="10" valign="top"> </td> </tr> <tr bgcolor="#D3DCE6"> <td colspan="6"></td> </tr> </table> <table width="854" border="0"> <tr bgcolor="#FFCC00"> <td><div align="center">Copywrite Uhhh... A VA Name. All Rights Reserved. | Link | Link | Link | Link | Link | </div></td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313266 Share on other sites More sharing options...
a1phanumeric Posted August 1, 2007 Share Posted August 1, 2007 Can you show the code that creates the array '$rt['iata']'? Cheers, Ed. Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313272 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 I'm pretty sure by this statement, that you're going to need to use $nt['iata'] instead of $rt['iata'] : <?php while($nt=mysql_fetch_array($rt)){ echo "Page info goes here. It gets called from the database"; ?> Because that is saying $rt is the query, and $nt is the array from the query. And where is that code at? Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313276 Share on other sites More sharing options...
a1phanumeric Posted August 1, 2007 Share Posted August 1, 2007 Yeah, I think KingPhillip is right... Ed. Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313280 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 I Tried while($nt=mysql_fetch_array($rt)){ echo '$rt[iata]'; } Still Doesnt work?! I dont get it it should be working? Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313287 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 replace it with this: while($nt=mysql_fetch_array($rt)){ echo $nt['iata']; } and tell us what it says Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313290 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 No Still getting error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\airlines.php on line 67 Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313296 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 <?php ... $dbase = $rt['iata']; echo $dbase; $query="select * from `air_".$dbase."`"; $rt=mysql_query($query); ?> ..Later in the code... <?php if ($info == home){ while($nt=mysql_fetch_array($rt)){ echo "$nt[iata]"; } } else echo 'error'; ?> From the looks of it, you're calling a variable ($dbase = $rt['iata']; ) from something that hasn't happened yet. I'm a little confused on what you are trying to do here. Could you explain your intentions? Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313302 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 i am creating a cms (Content management system) When you select a clan it appears in the top of the screen airlines.php?va=1234&info=homepage The ?va=1234 changes to whatever the 4 didgit code is of the airline. Now each airline has thier own Table in the datyabase starting with air_then Airline 4 digit number which in this case I have chosen IATA as the variable and the IATA is stored in the colum IATA. Now all airlines page views come from the exact same .php page execpt the 4 digit number tells the script on which table to load the information. So that admins can change the data for thier airline only. my problem is I cannot figure out how to connect to database air_ then the IATA I have posted my entire script before so you gutys can look over it! Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313318 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 Okay, that's much better. I'll give you a rough outline on what to do: <?php ... $clan_id_var = $_GET['va']; //do some variable cleaning here to protect against attacks $query="select * from `air_".$clan_id_var."`"; $rt=mysql_query($query) or die(mysql_error()); ?> ..Later in the code... <?php if ($info == home){ while($nt=mysql_fetch_array($rt)){ echo $nt['iata']; } } else { echo 'error'; } ?> Hope it helps/works =) noticed a typo, edited this line: echo "$nt['iata']"; to echo $nt['iata']; Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313328 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 OMG Thank You sooo much KingPhilip. You really are king of the code!? Lol. Ya thanks again, and again, and again. Ive been working on this so long and you come by and Bam its done Thanks again! (And again lol) TOPIC SOLVED!!!!!! God I love saying that^^ Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313337 Share on other sites More sharing options...
Philip Posted August 1, 2007 Share Posted August 1, 2007 lol, no problem. there are some things you're going to want to clean up, (example ($info == home) should be ($info == "home"), etc. Keep working on it, and always ask questions Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313340 Share on other sites More sharing options...
Crew-Portal Posted August 1, 2007 Author Share Posted August 1, 2007 Ya I am trying to get this script done as fast as I can cause a friend of mine is doing a thing with only one Virtual airline and I want to make a better script compatable with multiple Virtual airlines! Lol (Thanks Again) Quote Link to comment https://forums.phpfreaks.com/topic/62916-solved-multiple-tables-for-users/#findComment-313346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.