Jump to content

Cant figure this out, second pair of eyes please?


Centurian

Recommended Posts

Sure, but its a pretty massive file. I'll post a good chunk of it.

 

Its part of a function I use in a game I'm making. Basically, it generates a description of a particular unit. It works by connecting to my MySQL database, grabbing the matching data, then using a bunch of if statements to find problems with it.

 

function getcomment($user,$id)
{

$con = mysql_connect("localhost","admin","******");
if (!$con)
{
echo "Could not connect.";
}

$lols = mysql_select_db("********", $con);
if (!$lols)
{
echo "Could not select database.";
}

$result = mysql_query("SELECT * FROM ".$user."Crew WHERE id = $id ");
if (!$result)
{
echo "No result <BR>";
}



while($row = mysql_fetch_array($result))
  {

if ((int)$row['loyalty']<20)
{
if ($row['rank']="XO")
	{
		return "$row['Name']." is openly mutinous towards you - s/he is not suitable as an XO.";
		goto endsub;
	}
else
	{
		return "$row['Name']." is unhappy with your leadership.";
		goto endsub;
	}

endsub:
}

mysql_close($con);
}

 

 

Link to comment
Share on other sites

Assuming it'll work if you switch it to that, also added an equals sign since you were setting the variable = XO everytime, you need to work on learning how variables work in double/single quotes and when concatenation is required.

 

if ($row['rank']=="XO")
	{
		return $row['Name']." is openly mutinous towards you - s/he is not suitable as an XO.";
		goto endsub;
	}
else
	{
		return $row['Name']." is unhappy with your leadership.";
		goto endsub;
	}

 

More on your variables in strings....

("SELECT * FROM ".$user."Crew WHERE id = $id ")

 

That's a prime example right there - why did you leave the quotes on one but not the other?

Link to comment
Share on other sites

Thanks, I Applied Zurevs advice:

function getcomment($user,$id)
{

$con = mysql_connect("localhost","jameswit","Jordan");
if (!$con)
{
echo "Could not connect.";
}

$lols = mysql_select_db("jameswit_starship", $con);
if (!$lols)
{
echo "Could not select database.";
}

$result = mysql_query("SELECT * FROM ".$user."Crew WHERE id = ".$id);
if (!$result)
{
echo "No result <BR>";
echo "SELECT * FROM ".$user."Crew";
}



while($row = mysql_fetch_array($result))
  {

if ((int)$row['loyalty']<20)
{
if ($row['rank']=="XO")
	{
		return $row['Name']." is openly mutinous towards you - s/he is not suitable as an XO.";
		goto endsub;
	}
else
	{
		return $row['Name']." is unhappy with your leadership.";
		goto endsub;
	}
}

  }

endsub:

mysql_close($con);
}

 

The Quotes were left because PHP was looking for a variable called '$userCrew' when I removed the dots, and I need to words joined with no space between them. The thing with the equals signs was just my inexperience with this language. Thanks for pointing that out.

 

I'm still getting the same error. 'Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jameswit/www/www/MYSQL.php on line 106'

 

 

 

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.