Jump to content

[SOLVED] Or die isn't working properly.. I think.


DaVuLf

Recommended Posts

Hey there. I'm having an issue with the following set of commands:

 

			//Check to see if we already have an entry for the acquiror stock
			$acquiror_existence_query = "SELECT * FROM portfolio WHERE team='$team_name' AND stock='$acquiror' AND flag='0'";
			echo $acquiror_existence_query.'<br />';
			$acquiror_existence = mysql_query($acquiror_existence_query) or die(mysql_error());
			echo $acquiror_existence.'<br />';
			if($acquiror_existence){
				//Check to see the value of these shares
				$acquiror_value = mysql_result($acquiror_existence,0,"value");
				//Check the quantity that they have
				$acquiror_quantity = mysql_result($acquiror_existence,0,"quantity");
			} else {
				//If it doesn't exist, set it to 0.
				$acquiror_value = 0;
				$acquiror_quantity = 0;
			}

 

Most specifically, this is happening because I am running a check to see if $acquiror_existence is true (ie, it exists) then running the appropriate segment of the if statement. Here is the results of my echoes.

 

SELECT * FROM portfolio WHERE team='bcom4' AND stock='MRK' AND flag='0'
Resource id #15

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 15 in C:\Program Files\xampp\htdocs\wdt\events.php on line 109

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 15 in C:\Program Files\xampp\htdocs\wdt\events.php on line 111

 

For some reason this is giving me some errors. I don't quite understand, but if someone could clarify, or help out, that would be fantastic. As it is, the string that it is looking for is not actually in the 'portfolio' table. There is no line with that description, as a result it should return the error, and then it should follow into the 'else' segment of the if statement, as acquiror_existence would be switched to 'false'.

 

Thanks for any help,

 

DaVuLF

Your assumption that mysql_query() returns an error if no rows are found is the problem. Finding no matches is a valid result.

 

To check if rows are returned

 

if(mysql_num_rows($acquiror_existence) > 0)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.