Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:35:24+00:00 2026-06-07T12:35:24+00:00

I have the following code snippet that builds chained select boxes based on data

  • 0

I have the following code snippet that builds chained select boxes based on data pulled from MySQL.

The first select uses a DISTINCT on a column called PartTypeDescription. This code works awesome if the values in the column are numerical in nature (example: 11). You choose the first select and then the second select is populated as it should.

The problem occurs when the data is text (example: Plumbing). You choose Plumbing for example and the second select box is empty. I’m assuming the second query that builds the second select box is not working correctly. Is there something in the code below that does not allow text values?

/* Configure the select boxes */

if (isset($_GET['key'])) {
    $key = $_GET['key'];
    switch ($key) {
        case 'callTypeSelect':
            $select = new SelectBox('What vehicle are you working from?','Choose a vehicle');
            $res = mysql_query('SELECT DISTINCT PartTypeDescription FROM ' . DB_TABLE2);
            $callTypes = array();
            for ($i = 0; list($callType) = mysql_fetch_row($res); $i++) {
                $callTypes[] = $callType;
                $select->addItem($callType, 'brandSelect-' . $callType);
            }
            header('Content-type: application/json');
            echo $select->toJSON();
            break;
        default:
            if (strpos($key, 'brandSelect-') === 0) {
                $callType = str_replace('brandSelect-', '', $key);
                $resBrands = mysql_query('SELECT Invm_InventoryNumber FROM ' . DB_TABLE2
                    . ' WHERE PartTypeDescription  = ' . mysql_real_escape_string($callType) . " ORDER BY Invm_InventoryNumber");
                $select = new SelectBox('What part number are you looking for?', 'Pick a part');
                for ($i = 0; list($brand) = mysql_fetch_row($resBrands); $i++) {
                    $select->addItem($brand, 'result-' . $brand . '-' . $callType);
                }
                header('Content-type: application/json');
                echo $select->toJSON();
            } elseif (strpos($key, 'result-') === 0) {
                list($null, $brand, $callType) = explode('-', $key);
                 $res = mysql_query('SELECT * FROM ' . DB_TABLE2
                   . ' WHERE PartTypeDescription = \'' . mysql_real_escape_string($callType) . '\'
                 AND Invm_InventoryNumber = \'' . mysql_real_escape_string($brand) . "'");

                $markup = '';
                for ($i = 0; $row = mysql_fetch_assoc($res); $i++) {
                    //$row = array_map('htmlspecialchars', $row);    it looks like the items is already encoded
                    $markup .= <<<HTML
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:35:27+00:00Added an answer on June 7, 2026 at 12:35 pm

    You can’t escape characters inside of single quotes. For example:

    $x = 'I don\'t like tomatoes';
    

    That won’t escape the quote like you think it would and will cause problems. In your code with this line:

    $res = mysql_query('SELECT * FROM ' . DB_TABLE2
       . ' WHERE PartTypeDescription = \'' . mysql_real_escape_string($callType) . '\'
       AND Invm_InventoryNumber = \'' . mysql_real_escape_string($brand) . "'");
    

    You need to wrap strings with escape sequences with double quotes.

    $res = mysql_query('SELECT * FROM ' . DB_TABLE2
       . " WHERE PartTypeDescription = \'" . mysql_real_escape_string($callType) . "\'
       AND Invm_InventoryNumber = \'" . mysql_real_escape_string($brand) . "'");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code snippet from my PowerShell script that... Loops through a
I have the following code snippet, which loads data from a CSV file into
I have the following code snippet. SqlCommand cmd = new SqlCommand(SELECT FName,LName FROM EMPLOYEE_TABLE
I have following code snippet that i use to compile class at the run
I have the following code snippet that shows a list of numbers, and highlights
I have the following Groovy code snippet that is attempting to use operator overloading
I have the following code snippet that produces a compilation error: public List<string> batchaddresses;
I have the following code snippet from a HTML file: <div id=rwImages_hidden style=display:none;> <img
I have the following code snippet in one of my COBOL program. IF FIRST
I have the following code snippet: $.getJSON(http://localhost:8080/images, function(data) { var items = []; $.each(data,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.