Pi_Mastuh Posted October 8, 2006 Share Posted October 8, 2006 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? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 8, 2006 Share Posted October 8, 2006 you want it to check the value of the ID is a above 0 or a different value? Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted October 8, 2006 Author Share Posted October 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 8, 2006 Share Posted October 8, 2006 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:[code]$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";}[/code]but i am still not sure if thats what ur asking. Quote Link to comment Share on other sites More sharing options...
AliasXNeo Posted October 8, 2006 Share Posted October 8, 2006 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.[code]$sql = "SELECT * FROM `table` WHERE `id` = 1 AND `othernumber` > 0";$result = mysql_query($sql);if (mysql_num_rows($result){ echo "ERROR!";}[/code] Quote Link to comment Share on other sites More sharing options...
oracle259 Posted October 8, 2006 Share Posted October 8, 2006 from readin ur post i would agree with ProjectFear's approach. however i would suggest modifying the code as follows:[code]$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;}}[/code]This should work. It provides better scripting practice and some error handling. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted October 8, 2006 Author Share Posted October 8, 2006 I'm using this:[code]$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; } }[/code] and [code]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>"; }[/code] but the pet i'm using to test has 3 items equipped when it should only be 1. It's not blocking it. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 9, 2006 Share Posted October 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.