Jump to content


Photo

Database querying help.


  • Please log in to reply
2 replies to this topic

#1 k4pil

k4pil
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 March 2006 - 12:05 AM

Hi there. This should be a quickie...

I am inserting data into my database as below;

$query = "INSERT INTO product VALUES ('','$prodName','$prodDesc','$supplier','$costPound', '$costPence')"; 
    mysql_query($query); 
    

All values are passed from a form and its all working fine.

I then want to query the databse and output products searched for by the user. e.g.
$query = "SELECT * FROM product WHERE productID = '$ID' OR prodName = '$prodName' OR prodDesc = '$prodDesc' OR supplier = '$supplier' OR costPound = '$costPound' OR costPence = '$costPence'";
$result = mysql_query($query); 
$num = mysql_numrows($result);

The problem is when the user specifies he/she wants the output contain the row he/she wants but also all other rows that contain the value 0. for example if a product cost £10.00 this is output because in the costPence column the value exists as 0.

How can i avoid this? Is there a method or some logic that i need??

Thanks in advance as always ppl!

#2 running_out_of_imagination

running_out_of_imagination
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationSouthampton, UK

Posted 01 March 2006 - 12:31 AM

If you want the products that cost £10,00 you have to use:

costPound = '$costPound' AND costPence = '$costPence'";

Maybe merge both fileds as no one will look up for something that costs £x,65 beeing x any value

#3 k4pil

k4pil
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 March 2006 - 10:59 PM

The cost thing was an example...i was illustrating what the problem i a, having is.

For example, when i search for a customer

$query = "SELECT * FROM customer WHERE name = '$name'";

I get output everything where name = '$name' as well as every row which does not have an entry for name in the customer table.


Any help any1???




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users