Jump to content
  • Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~
teensicle

Multiply SQL Queries Retrieving Column Information

Recommended Posts

i checked the main site and it has been a whole heap of help so far. However im not sure how to accomplish a specific task and im now stuck on this. I have the following query: SELECT * FROM chjadb_vehicles WHERE v_make ='$make' AND v_year= '$year' The following statement works fine. However what i want is to add more query criterias such as body type, transmission and thing like that. How do i set something like that. I tried doing it like this: SELECT * FROM chjadb_vehicles WHERE v_make ='$make', v_year= '$year', v_transmission = '$trans' Doesn't work however :( any help would be appreciated!

Share this post


Link to post
Share on other sites

you can use logical AND to add more condition http://dev.mysql.com...xpressions.html <=Resource

Edited by birbal

Share this post


Link to post
Share on other sites

I am developing a website where by people can buy and sell new or used cars. I want to set up a simple filter using php and sql statements and also of course html select boxes (drop down options). I have gotten all the other options to work with help and trust me it has been greatly appreciated. However i have been trying to get the "price filter" to work and been getting no where. Below is what my select box in html look like. <select name="price" size="0"> <option value="100000">Under $100,000</option><option value="<?php echo " BETWEEN '100000' AND '250000' "?>">Between $100,000 and $250,000</option><option value=">250000<500000">Between $250,000 and $500,000</option><option value=">500000<750000">Between $500, 000 and $750,000</option><option value=">7500000">Over $750,000</option> </select> This is my $_POST statement for the price variable: $price = mysql_real_escape_string($_POST['price']); This is my sql statement: $sql = sprintf("SELECT * FROM `chjadb_vehicles` WHERE `v_make` LIKE '$make'AND `v_year` = '$year'AND `v_trans` LIKE '$trans'AND `condition` LIKE '$cond' AND `b_style` LIKE '$b_style' AND `v_price` '$price'"); After which i have a basic loop that should print the results. Now from what i understand (correct or not), when the user selects a specific option from the drop down menu the value from "option value" is passed to the $_POST statement. After which it should replace $price with the actual text BETWEEN '100000' AND '250000', completing the query statement. So the final statement printed from the sql statement should be: "SELECT * FROM `chjadb_vehicles` WHERE `v_make` LIKE '$make'AND `v_year` = '$year'AND `v_trans` LIKE '$trans'AND `condition` LIKE '$cond' AND `b_style` LIKE '$b_style' AND `v_price` BETWEEN '100000' AND '250000'"` However i get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''BETWEEN 100000 AND 250000'' at line 8 Any ideas as to where i went wrong? Thanks Regards,D. Ruddock

Edited by teensicle

Share this post


Link to post
Share on other sites

Remove the quotes around the price variable. This: `b_style` LIKE '$b_style' AND `v_price` '$price' is being replaced to this: `b_style` LIKE '$b_style' AND `v_price` 'BETWEEN '100000' AND '250000'' You can see that the error message includes that first quote before BETWEEN.

Share this post


Link to post
Share on other sites

My new select option:

Price	<select name="price" size="0">	<option value="< 100000">Under $100,000</option><option value=">= 100000 AND `v_price` <= 250000">Between $100,000 and $250,000</option><option value=">= 250000 AND `v_price` <= 500000">Between $250,000 and $500,000</option><option value=">= 500000 AND `v_price` <= 750000">Between $500, 000 and $750,000</option><option value=">7500000">Over $750,000</option>	</select>

PHP CODE:

$sql = sprintf("SELECT *FROM  `chjadb_vehicles`WHERE  `v_make` LIKE  '$make'AND  `v_year` =  '$year'AND  `v_trans` LIKE  '$trans'AND  `v_price` $priceAND  `condition` LIKE  '$cond'AND  `b_style` LIKE  '$b_style'");

Thanks it now works! i find that when i set a criteria and press submit the options reset itself. How can i control that? if you notice the make goes back to BMW, which is at the top of the select query list and also does the other options see example below: P.S ignore the horrible layout just trying to get the functionality working criteria.jpg

Edited by teensicle

Share this post


Link to post
Share on other sites

When you're writing out the options for the dropdown you'll need to check for each option if the value for that option is the value that was submitted in $_POST, and if it was then add a "selected" attribute for the option to indicate that it should be selected. http://www.w3schools.com/tags/att_option_selected.asp

Share this post


Link to post
Share on other sites

So i know it's been a while but i'm back on the grind! ^_^. Can anyone suggest how i can include a option that will display "ALL" in a select box

Share this post


Link to post
Share on other sites

The common way would be to add an option with a blank value or something, and in the PHP code if that field is blank then don't add a filter for that field in the WHERE clause in the query. Only include filters in the WHERE clause for fields that they have chosen values for.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×