Jump to content


Photo

How do I...


  • Please log in to reply
7 replies to this topic

#1 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 08 October 2006 - 01:29 AM

I want to have it seach for an ID number in a table and if it finds it then to check if a value is above zero, if it is then dissplay error message one. If it's not, see if a second value is above zero and if it is display error message 2. How do I do that?
Schroedinger's Cat walks into a bar.
And doesn't.

#2 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 08 October 2006 - 01:37 AM

you want it to check the value of the ID is a above 0 or a different value?
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 08 October 2006 - 01:43 AM

a different value. Each row has an ID, a value, and a 2nd value. One of the 2 non-ID values is above zero and the other is zero.
Schroedinger's Cat walks into a bar.
And doesn't.

#4 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 08 October 2006 - 01:50 AM

ok, i c, well could do it a few differnet ways but couldnt u just get both values, check the first one then if its above 0 display error if its not check the second one etc.
like this:
$row = mysql_fetch_array(mysql_query("SELECT * FROM `table` WHERE `id`='1'"));

if($row['value1'] > 0){
echo "error msg #1";
}elseif($row['value2'] > 0){
echo "error msg #2";
}else{
echo "they are both 0";
}

but i am still not sure if thats what ur asking.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#5 AliasXNeo

AliasXNeo
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 08 October 2006 - 03:47 AM

Well, i'm going to explain what I think you're saying. You want to check for a row with a certain id number and display an error if another value in that row is above zero.

$sql = "SELECT * FROM `table` WHERE `id` = 1 AND `othernumber` > 0";
$result = mysql_query($sql);
if (mysql_num_rows($result)
{
     echo "ERROR!";
}


#6 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 08 October 2006 - 03:59 AM

from readin ur post i would agree with ProjectFear's approach. however i would suggest modifying the code as follows:

$query = sprintf("SELECT * FROM table WHERE id='1'");
$result = mysql_query($query);
if (!$result) {
die ('Invalid Query' . mysql_error());
}

$nums = mysql_num_rows($result);
if (!$nums) {
die ('Sorry, no entries found.');
}

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

if($row['value1'] > 0){
die (error msg #1');
}elseif($row['value2'] > 0){
die ('error msg #2');
}else{
echo "they are both 0";
break;
}

}

This should work. It provides better scripting practice and some error handling.

#7 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 08 October 2006 - 04:23 PM

I'm using this:
$sql = "SELECT count(*) as atkItem FROM Dualequip WHERE petID = '$monopetID'";
   	$result1 = mysql_query($sql);
	$query_data = mysql_fetch_array($result1);
	$atkItem = $query_data['atkItem'];
	
if ($atkItem > 0)
	{
		$SQL = "SELECT * FROM Dualequip WHERE petID = '$monopetID'";
			$result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
			$query_data = mysql_fetch_array($result);
			$atkValue = $query_data['atkValue'];
			$defValue = $query_data['defValue'];
if ($atkValue > 0)
	{
		$no = 0;
	}
elseif ($defValue > 0)
	{
		$no = 1;
	}
else 
	{
		$no = 3;
	}
	}
and
if ($no == 0 AND $food == "Weapon" AND $atkValue > o)
	{
		echo "<p align=center>$monopetName already has an attack item equipped!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
	}
elseif ($no == 1 AND $food == "Weapon" AND $defValue > o)
	{
		echo "<p align=center>$monopetName already has an defense item equipped!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
	}
elseif ($food == "Weapon")
	{
		$sql = "INSERT INTO Dualequip (preuserID, petID, itemID, atkValue, defValue)
		VALUES ('$preuserID', '$monopetID', '$itemID', '$atkValue', '$defValue')";
		mysql_query("DELETE FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'");

		$result = mysql_query($sql) or die("There was an error equiping the weapon. Sorry.");
				echo "<p align=center>You have equipped <b>".$monopetName."</b> with <b>".$itemName."</b>!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
		}
but the pet i'm using to test has 3 items equipped when it should only be 1. It's not blocking it.
Schroedinger's Cat walks into a bar.
And doesn't.

#8 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 09 October 2006 - 08:29 AM

i read most of it but i think i can c an eror. ur using 'o' instead if '0' in the if statements for your second code. take a look. but i am not sure if thats ment to b like that.
Good luck with your coding.
Jason / ProjectFear / Jaysonic




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users