Jump to content

Database querying help.


k4pil

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.