Jump to content

[SOLVED] mysql joins


Locked

Recommended Posts

I dont know how to explain it so ill show you the code

 

$select=$q("SELECT UserExp.CrimeExp, User.Nerve,  CrimeList.ExpNeeded, CrimeList.ExpGain, CrimeList.ExpLoss, CrimeType.Nerve FROM UserExp,User,CrimeList,CrimeType
where CrimeList.CrimeID=CrimeType.ID AND CrimeType.ID='$_GET[type]'")or die(mysql_error());
$select=mysql_fetch_array($select);
$Test=$select[user.Nerve];
$Test2=$select[CrimeType.Nerve];
echo("Test: $Test Test2: $Test2 ");
if($select[user.Nerve]<$select[CrimeType.Nerve]){

Basicly there both returning null, any advice in getting around this problem

Link to comment
Share on other sites

You should put "type" in quotes in the $_GET[] array. I'm not sure it will change anything, but it is a literal string in the array, so it should be called as such. You will need curly braces too, if you do that.

...CrimeType.ID='{$_GET['type']}'")...

 

If that doens't fix anything, post the layout of the tables with some sample data and what you are trying to get the query to return.

Link to comment
Share on other sites

I think the problem is that the both tables have a feild called 'nerve' in it, when i call from the exact same query i use $select[CrimeExp] but because theres 2 nerve feilds i tryed using TableName.Feild both turns out null leading me to belive that the name is wrong, everything else works just the nerve turns out null

 

<?php
$select=$q("SELECT UserExp.CrimeExp, User.Nerve,  CrimeList.ExpNeeded, CrimeList.ExpGain, CrimeList.ExpLoss, CrimeType.Nerve FROM UserExp,User,CrimeList,CrimeType
where CrimeList.CrimeID=CrimeType.ID AND CrimeType.ID='$_GET[type]'")or die(mysql_error());
$select=mysql_fetch_array($select);
$Test=$select[user.Nerve];
$Test2=$select[CrimeType.Nerve];
echo("Test: $Test Test2: $Test2 ");
if($select[user.Nerve]<$select[CrimeType.Nerve]){
	if($select[CrimeExp]>=$select[ExpNeeded])$pass=rand(0,13);
	else $pass=rand(0,6);
		$pass1=rand(1,3);
		echo $pass;
			if($pass>=7){//Passed
				$exp=$select[ExpNeeded]*2;
				$ExpGain=$select[ExpGain]/2;
				$ExpGain=rand($ExpGain,$select[ExpGain]);
				$pass='CrimeList.Good'.$pass1;
				$select=$q("SELECT UserExp.CrimeExp, $pass , CrimeList.MoneyGain, CrimeList.JewelGain, CrimeList.ItemGain, CrimeType.Nerve FROM UserExp 	,CrimeList,CrimeType where CrimeList.CrimeID=CrimeType.ID AND CrimeType.ID='$_GET[type]'")or die(mysql_error());
?>

 

Everything there works just both nerves turn out blank

Link to comment
Share on other sites

One of the SELECTs with the nerve field needs to define it as a different name.

"SELECT User.Nerve, CrimeType.Nerve as CTNerve FROM...";

 

Then you can use Nerve as the one from User and CTNerve as the one from CrimeType. You could even set User.Nerve as UNerve, or something, if you wanted.

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.