Jump to content

Inner Join Issues (First time I have tried)


Go to solution Solved by WAMFT1,

Recommended Posts

I have been trying to figure this out for days but no luck so far.

 

I have two tables which I want to pull info from and from what I read a join query is the way to go. I need to pull the info from the bank table based on the login id in the users table. I keep getting a black page result or a Data not Found result. Because this is the first time I have tried a join query I don't really know what I am doing. Is anyone able to give me some advice?

<?php
 		//if the login session does not exist therefore meaning the user is not logged in
		if(strcmp($_SESSION['uid'],"") == 0){
			//display and error message
			header('Location: ../index.php');
		}else{
			//otherwise continue the page
 			//this is out update script which should be used in each page to update the users online time
			$time = date('U')+50;
			$update = mysql_query("UPDATE `e-users` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");
			?>
			<?php
 		//make sure you close the check if their online
		}
 		?>     
<?php
require("../edb.php");
$result = mysql_query("SELECT AcctName, BSB1, BSB2, AccNumber, Adviser, Bank
 FROM a-bank
 JOIN e-users
 ON a-bank.Adviser = e-users.id;
 WHERE e-users.id = '".$_SESSION['uid']."'");

if (!$result) 
		{
		die("Error: Data not found..");
		}
	$AcctName=$test['AcctName'];
?>

Since your table names have a - in them, you have to quote them with backticks (`). With out them the - will be treated as a minus and cause a syntax error.

 

As a tip, you should not use any special characters in your table or column names. Stick with a-z, 0-9, and _.

I have renamed the tables to remove the possibility of any syntax error but still having problems with the page working. Any ideas, I keep getting Data not Found

<?php
require("../edb.php");
$result = mysql_query("SELECT AcctName, BSB1, BSB2, AccNumber, Adviser, Bank
 FROM abank
 JOIN eusers
 ON abank.Adviser=eusers.id;
 WHERE abank.Adviser = '".$_SESSION['uid']."'");

if (!$result) 
		$AcctName=$test['AcctName'];
		$BSB1=$test['BSB1'];
		$BSB2=$test['BSB2'];
		$AccNumber=$test['AccNumber'];
		$Adviser=$test['Adviser'];
		$Bank=$test['Bank'];		
			{
		die("Error: Data not found..");
		}
?>

Something seems to be wrong with this code:

 

if (!$result) 
		$AcctName=$test['AcctName'];
		$BSB1=$test['BSB1'];
		$BSB2=$test['BSB2'];
		$AccNumber=$test['AccNumber'];
		$Adviser=$test['Adviser'];
		$Bank=$test['Bank'];	
			{
		die("Error: Data not found..");
		}
That isn't even syntactically correct, but assuming we're missing something, the condition is incorrect. It would be this instead:

 

 

if ($result) { 
		$AcctName=$test['AcctName'];
		$BSB1=$test['BSB1'];
		$BSB2=$test['BSB2'];
		$AccNumber=$test['AccNumber'];
		$Adviser=$test['Adviser'];
		$Bank=$test['Bank'];		
} else {
		die("Error: Data not found..");
}

i have marked this thread solved for you to help prevent others from spending time trying to fix things in an abandoned thread.

 

as stated in the thread you started after this one, the following logic does not mean that data was not found, it means the the query failed with an error of some kind -

if (!$result)
        {
        die("Error: Data not found..");
        }

 

 

using your database library's error reporting function (mysql_error() in this case) would have pointed to the part of the query where mysql found a problem.

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.