Jump to content

trouble with WHERE query


longhorn14

Recommended Posts

I am missing something here. I would like a query where I can have records displayed according to two different criteria. I can get it done with just one, such as

[php:1:ceb2ecabf9]<?php

 

$query=\"SELECT * FROM customers WHERE cust_type=\'$cust_type\'\";

 

?>[/php:1:ceb2ecabf9]

but, when I add another field, it displays nothing and I get no errors. Ideally, I would like to have the URL indicate what I want displayed (www.somedomain.com/file.php?cust_type=5&cust_subtype=Other). A more comprehensive code snippet is below. Thanks a ton,

nat

 

[php:1:ceb2ecabf9]<?php

<?

include(\"dbcustomers.inc.php\");

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( \"Unable to select database\");

$query=\"SELECT * FROM customers WHERE cust_type=\'$cust_type\' AND WHERE cust_subtype=\'$cust_subtype\'\";

 

$result=mysql_query($query);

 

 

 

mysql_close();

$ctype=\"contacts\";

echo \"<b><center>Customer Database</center></b><br><br>\";

 

?>

?>[/php:1:ceb2ecabf9]

Link to comment
Share on other sites

Hey

 

Say someone goes to this url: www.somedomain.com/file.php?cust_type=5&cust_subtype=Other

 

the query could act according to the url like this:

$query="SELECT * FROM customers WHERE cust_type=\'".$_GET[\'cust_type\']."\' AND cust_subtype=\'".$_GET[\'cust_subtype\']."\'";

 

the $_GET fetches the GET value from the url (?variable=value)

Link to comment
Share on other sites

Well, I tried it with two \"AND\" statements in the query and it worked fine.

Here was the query:

[php:1:584218dfa6]<?php

$query=\"SELECT * FROM customers WHERE state_res=\'\".$_GET[\'state_res\'].\"\' AND cust_type=\'\".$_GET[\'cust_type\'].\"\' AND cust_subtype=\'\".$_GET[\'cust_subtype\'].\"\'\";

?>[/php:1:584218dfa6]

 

The URL for this is:

http://www.racksandfins.com/guides_test.ph...fishing%20guide

 

Thanks for the help!

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.