Jump to content

Archived

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

k4pil

Database querying help.

Recommended Posts

Hi there. This should be a quickie...

I am inserting data into my database as below;

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

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.
[code]
$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);
[/code]

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!

Share this post


Link to post
Share on other sites
If you want the products that cost £10,00 you have to use:

[code]costPound = '$costPound' AND costPence = '$costPence'";[/code]

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

Share this post


Link to post
Share on other sites
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???

Share this post


Link to post
Share on other sites

×

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.