Jump to content

[SOLVED] Multiple Tables For Users


Crew-Portal

Recommended Posts

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)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

<?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?  ???

Link to comment
Share on other sites

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());
?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

OMG Thank You sooo much KingPhilip. You really are king of the code!? ;D 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^^

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.