Jump to content


Photo

MySQL "OR"


  • Please log in to reply
3 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 September 2006 - 12:26 PM

Hello could someone take a look at this for me. It should just list any model where the Air Pressure Switch is 39800140 OR the Auto Air Vent is 39810370. I get a couple of error messages and I don't think I've got the "Or" bit correct.


$db = mysql_connect("localhost", "root", "password")or die ("Error connecting to database.");
mysql_select_db("Telephonelist",$db) or die ("Couldn't select the database.");
$result = mysql_query("SELECT * FROM tbl_parts WHERE Air_Pressure_Switch='39800140' || Auto_Air_Vent='39810370'",$db);        
$row = mysql_fetch_array($result);

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

    printf("<b class='Body2'>%s</b><br>", $row["Model"]);
	
}




I get the following errors:




Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Intranet v3\TEST\Spares\test.php on line 11

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Intranet v3\TEST\Spares\test.php on line 13
"Whats wrong with the cat?" - Mrs Schrödinger

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 11 September 2006 - 12:29 PM

in SQL, you actually have to us "OR" not the "||" operator:
SELECT * FROM tbl_parts WHERE Air_Pressure_Switch='39800140' OR Auto_Air_Vent='39810370'

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 °°Ben³

°°Ben³
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationGermany / Remagen

Posted 11 September 2006 - 12:50 PM

Use the mysql_error() function in future to receive a more detailed error message!
i.e.
$resource = mysql_query($sql) or exit(mysql_error());

That is really helpful while developing!
desktop and web development ;)
---
English is not my native language. Please excuse if I made some errors in expression.

#4 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 September 2006 - 01:42 PM

Thank you Dan and Obsidian both very helpful!  ;D
"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users